net.sf.jameleon.data
Class CsvDataDriver

java.lang.Object
  extended by net.sf.jameleon.data.CsvDataDriver
All Implemented Interfaces:
DataDriver

public class CsvDataDriver
extends Object
implements DataDriver

Am implementation of @{link DataDriver} for CSV Files. This implementation can accept different delimiters. The default delimiter is ','.


Field Summary
protected  File csvFile
           
protected static char DEFAULT_DELIMETER
           
protected  char delimiter
           
protected  String encoding
           
protected  BufferedReader in
           
protected  List keys
           
protected  String line
           
 
Constructor Summary
CsvDataDriver()
          Default construtor.
CsvDataDriver(File csvFile)
          Sets the file to be read in to csvFile
CsvDataDriver(File csvFile, char delimiter)
          Sets the file and the delimiter of the file to be read in
 
Method Summary
 void close()
          Closes the handle to the data source
 char getDelimiter()
          Gets the field delimiter for the csv file
 String getEncoding()
          Gets the encoding of the csv file.
 File getFile()
          Gets the CSV file used as a datasource.
 Map getNextRow()
          Gets the next row from the data source
protected  void getNextUcommentedLine()
           
 boolean hasMoreRows()
          Tells whether the data source has another row
protected  boolean isLineCommented(String line)
           
 void open()
          Opens the handle to the data source
protected  List parseLine(String line, boolean keysLine)
           
protected  void readLine()
           
 void setDelimiter(char delimiter)
          Sets the field delimiter for the csv file
 void setEncoding(String encoding)
          Sets the encoding of the csv file.
 void setFile(File csvFile)
          Sets the CSV file used as a datasource.
protected  void setKeys()
          Sets the key columns from the csv file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

csvFile

protected File csvFile

in

protected BufferedReader in

DEFAULT_DELIMETER

protected static final char DEFAULT_DELIMETER
See Also:
Constant Field Values

delimiter

protected char delimiter

encoding

protected String encoding

keys

protected List keys

line

protected String line
Constructor Detail

CsvDataDriver

public CsvDataDriver()
Default construtor. After calling this constructor, setFile() will need to be set.


CsvDataDriver

public CsvDataDriver(File csvFile)
Sets the file to be read in to csvFile

Parameters:
csvFile - - the file to be used for parsing

CsvDataDriver

public CsvDataDriver(File csvFile,
                     char delimiter)
Sets the file and the delimiter of the file to be read in

Parameters:
csvFile - - the file to be used for parsing
delimiter - - the field delimiter of the csv file.
Method Detail

close

public void close()
Closes the handle to the data source

Specified by:
close in interface DataDriver

open

public void open()
          throws IOException
Opens the handle to the data source

Specified by:
open in interface DataDriver
Throws:
IOException - when the data source can not be found.

getEncoding

public String getEncoding()
Gets the encoding of the csv file. Defaults to UTF-8

Returns:
the encoding of the csv file

setEncoding

public void setEncoding(String encoding)
Sets the encoding of the csv file.

Parameters:
encoding - - the encoding of the csv file

getFile

public File getFile()
Gets the CSV file used as a datasource.

Returns:
the CSV file used as a datasource.

setFile

public void setFile(File csvFile)
Sets the CSV file used as a datasource.

Parameters:
csvFile - - the CSV file used as a datasource.

getNextRow

public Map getNextRow()
Gets the next row from the data source

Specified by:
getNextRow in interface DataDriver
Returns:
a key-value HashMap representing the data row or null if no data row is available
Throws:
IllegalStateException - if there are more values than keys

getDelimiter

public char getDelimiter()
Gets the field delimiter for the csv file

Returns:
the field delimiter for the csv file

setDelimiter

public void setDelimiter(char delimiter)
Sets the field delimiter for the csv file

Parameters:
delimiter - - the field delimiter for the csv file

setKeys

protected void setKeys()
Sets the key columns from the csv file


hasMoreRows

public boolean hasMoreRows()
Tells whether the data source has another row

Specified by:
hasMoreRows in interface DataDriver
Returns:
true if the data source still has more rows

parseLine

protected List parseLine(String line,
                         boolean keysLine)

isLineCommented

protected boolean isLineCommented(String line)

readLine

protected void readLine()

getNextUcommentedLine

protected void getNextUcommentedLine()


Copyright © 2003-2008 Christian Hargraves. All Rights Reserved.