The Encog Project

org.encog.util
Class ReadCSV

java.lang.Object
  extended by org.encog.util.ReadCSV

public class ReadCSV
extends java.lang.Object

ReadCSV: Read and parse CSV format files.


Constructor Summary
ReadCSV(java.io.InputStream is, boolean headers, char delim)
          Construct a CSV reader from an input stream.
ReadCSV(java.lang.String filename, boolean headers, char delim)
          Construct a CSV reader from a filename.
 
Method Summary
 void close()
          Close the file.
static java.lang.String displayDate(java.util.Date date)
          Format a date.
 java.lang.String get(int i)
          Get the specified column as a string.
 java.lang.String get(java.lang.String column)
          Get the column by its string name, as a string.
 java.util.Date getDate(java.lang.String column)
          Get the column as a date.
 double getDouble(int index)
          Get the column as a double specified by index.
 double getDouble(java.lang.String column)
          Get the specified column as a double.
 int getInt(java.lang.String col)
          Obtain a column as an integer referenced by a string.
 boolean next()
          Read the next line.
static java.util.Date parseDate(java.lang.String when)
          Parse a date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadCSV

public ReadCSV(java.io.InputStream is,
               boolean headers,
               char delim)
        throws java.io.IOException
Construct a CSV reader from an input stream.

Parameters:
is - The InputStream to read from.
headers - Are headers present?
delim - What is the delimiter.
Throws:
java.io.IOException - An IO error occurred.

ReadCSV

public ReadCSV(java.lang.String filename,
               boolean headers,
               char delim)
        throws java.io.IOException
Construct a CSV reader from a filename.

Parameters:
filename - The filename.
headers - The headers.
delim - The delimiter.
Throws:
java.io.IOException - An IO exception occured.
Method Detail

displayDate

public static java.lang.String displayDate(java.util.Date date)
Format a date.

Parameters:
date - The date to format.
Returns:
The formatted date.

parseDate

public static java.util.Date parseDate(java.lang.String when)
Parse a date.

Parameters:
when - The date string.
Returns:
The parsed date.

close

public void close()
           throws java.io.IOException
Close the file.

Throws:
java.io.IOException - An exception occured.

get

public java.lang.String get(int i)
Get the specified column as a string.

Parameters:
i - The column index, starting at zero.
Returns:
The column as a string.

get

public java.lang.String get(java.lang.String column)
Get the column by its string name, as a string. This will only work if column headers were defined that have string names.

Parameters:
column - The column name.
Returns:
The column data as a string.

getDate

public java.util.Date getDate(java.lang.String column)
                       throws java.text.ParseException
Get the column as a date.

Parameters:
column - The column header name.
Returns:
The column as a date.
Throws:
java.text.ParseException - If an error occured while parsing.

getDouble

public double getDouble(int index)
Get the column as a double specified by index.

Parameters:
index - The column index, starting at zero.
Returns:
The data at the specified column.

getDouble

public double getDouble(java.lang.String column)
Get the specified column as a double.

Parameters:
column - The column name that we want to get.
Returns:
The column data as a double.

getInt

public int getInt(java.lang.String col)
Obtain a column as an integer referenced by a string.

Parameters:
col - The column header name being read.
Returns:
The column data as an integer.

next

public boolean next()
             throws java.io.IOException
Read the next line.

Returns:
True if there are more lines to read.
Throws:
java.io.IOException - An error occured.

The Encog Project