smithers.files
Class CSVReader

java.lang.Object
  extended by smithers.files.CSVReader

public class CSVReader
extends java.lang.Object

Reads data from a CSV file.


Constructor Summary
CSVReader(java.io.File file)
          Creates a CSVReader which reads from the specified file.
CSVReader(java.lang.String fileName)
          Creates a CSVReader which reads from the specified file.
 
Method Summary
 java.lang.String currentRow()
          Returns the current row of the table.
 java.lang.String getCell(int i)
          Returns the specified cell of the current row of the table.
 java.lang.String nextRow()
          Reads the next table row from the file.
 int numColumns()
          Returns the number of columns in the current row of the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVReader

public CSVReader(java.lang.String fileName)
          throws java.io.FileNotFoundException
Creates a CSVReader which reads from the specified file.

Parameters:
fileName - the name of the file to read from
Throws:
java.io.FileNotFoundException - if the file is not found

CSVReader

public CSVReader(java.io.File file)
          throws java.io.FileNotFoundException
Creates a CSVReader which reads from the specified file.

Parameters:
file - the file to read from
Throws:
java.io.FileNotFoundException - if the file is not found
Method Detail

currentRow

public java.lang.String currentRow()
Returns the current row of the table. This method returns the same value as the most recent call to nextRow(), if there was no such call, this returns null.

Returns:
the current table row as a single String

numColumns

public int numColumns()
Returns the number of columns in the current row of the table.

Returns:
the number of columns in the current table row

getCell

public java.lang.String getCell(int i)
Returns the specified cell of the current row of the table. This method will accept an index from 0 to numColumns().

Parameters:
i - the column index
Returns:
the value of the cell
Throws:
java.lang.IndexOutOfBoundsException - if i<0 || i>= numColumns()

nextRow

public java.lang.String nextRow()
                         throws java.io.IOException
Reads the next table row from the file. This method reads the next row of data from the file, updates the currentRow(), numColumns() and getCell(int) methods and returns the row as a String. If the end of the file has already been reached, null is returned. If the end of the file is reached before the end of the row (i.e. when the quotes defining a cell are unclosed), the cell (and row) are assumed to be complete.

Returns:
the new table row as a single String
Throws:
java.io.IOException - if one occurs