JMSLTM Numerical Library 4.0

com.imsl.io
Class FlatFile

java.lang.Object
  extended bycom.imsl.io.AbstractFlatFile
      extended bycom.imsl.io.FlatFile
All Implemented Interfaces:
ResultSet

public class FlatFile
extends AbstractFlatFile

Reads a text file as a ResultSet.

FlatFile extends AbstractFlatFile to handle text flat files.

As the file is read, it is split into lines using the BufferedReader.readLine() method. Each line is then split into tokens using a Tokenizer. Finally, each token string is converted into an Object using a Parser.

Parser is an interface defined within this class for converting a String into an Object. Parser objects for standard types are defined as static members of this class. By default, for each column its class is used to select one of these predefined parsers to parse that column.

See Also:
Example: Comma Separated Data, Example: Space Separated Data

Nested Class Summary
static interface FlatFile.Parser
          Defines a method that parses a String into an Object.
 
Nested classes inherited from class com.imsl.io.AbstractFlatFile
AbstractFlatFile.FlatFileSQLException
 
Field Summary
static FlatFile.Parser PARSE_BYTE
          Implements a Parser that converts a String to a Byte.
static FlatFile.Parser PARSE_DOUBLE
          Implements a Parser that converts a String to a Double.
static FlatFile.Parser PARSE_FLOAT
          Implements a Parser that converts a String to a Float.
static FlatFile.Parser PARSE_INTEGER
          Implements a Parser that converts a String to a Integer.
static FlatFile.Parser PARSE_LONG
          Implements a Parser that converts a String to a Long.
static FlatFile.Parser PARSE_SHORT
          Implements a Parser that converts a String to a Short.
 
Fields inherited from interface java.sql.ResultSet
CLOSE_CURSORS_AT_COMMIT, CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
 
Constructor Summary
FlatFile(BufferedReader reader)
          Creates a FlatFile with the CSV tokenizer.
FlatFile(BufferedReader reader, Tokenizer tokenizer)
          Creates a FlatFile from a BufferedReader.
FlatFile(String filename)
          Creates a FlatFile from a CSV file.
FlatFile(String filename, Tokenizer tokenizer)
          Creates a FlatFile from a file with the default tokenizer.
 
Method Summary
protected  byte[] doGetBytes(int columnIndex)
          Gets the value of the designated column in the current row as a byte array.
protected  boolean doNext()
          Moves the cursor down one row from its current position.
 int getColumnCount()
          Returns the number of columns in this ResultSet object.
 Object getObject(int columnIndex)
          Gets the value of the designated column in the current row of this ResultSet object as an Object in the Java programming language.
protected  String readLine()
          Reads and returns a line from the input.
protected  void setColumnClass(int columnIndex, Class columnClass)
          Sets a column class.
protected  void setColumnParser(int columnIndex, FlatFile.Parser columnParser)
          Sets the Parser for the specified column.
protected  void setDateColumnParser(int columnIndex, String pattern, Locale locale)
          Creates for a pattern string and sets the Parser for the specified column.
 
Methods inherited from class com.imsl.io.AbstractFlatFile
absolute, afterLast, beforeFirst, beginGet, cancelRowUpdates, clearWarnings, close, deleteRow, findColumn, findColumnName, first, getArray, getArray, getAsciiStream, getAsciiStream, getBigDecimal, getBigDecimal, getBinaryStream, getBinaryStream, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getCharacterStream, getCharacterStream, getClob, getClob, getColumnClass, getConcurrency, getCursorName, getDate, getDate, getDate, getDate, getDouble, getDouble, getFetchDirection, getFetchSize, getFloat, getFloat, getInt, getInt, getLong, getLong, getMetaData, getObject, getObject, getObject, getRef, getRef, getRow, getShort, getShort, getStatement, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getType, getURL, getURL, getWarnings, insertRow, isAfterLast, isBeforeFirst, isFirst, isLast, last, moveToCurrentRow, moveToInsertRow, next, previous, refreshRow, relative, rowDeleted, rowInserted, rowUpdated, setColumnName, setFetchDirection, setFetchSize, setWarning, updateArray, updateArray, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBlob, updateBlob, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateClob, updateClob, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateRef, updateRef, updateRow, updateShort, updateShort, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp, wasNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.ResultSet
getBigDecimal, getBigDecimal, getUnicodeStream, getUnicodeStream
 

Field Detail

PARSE_BYTE

public static final FlatFile.Parser PARSE_BYTE
Implements a Parser that converts a String to a Byte.

See Also:
Byte.valueOf(String)

PARSE_DOUBLE

public static final FlatFile.Parser PARSE_DOUBLE
Implements a Parser that converts a String to a Double.

See Also:
Double.valueOf(String)

PARSE_FLOAT

public static final FlatFile.Parser PARSE_FLOAT
Implements a Parser that converts a String to a Float.

See Also:
Float.valueOf(String)

PARSE_INTEGER

public static final FlatFile.Parser PARSE_INTEGER
Implements a Parser that converts a String to a Integer.

See Also:
Integer.valueOf(String)

PARSE_LONG

public static final FlatFile.Parser PARSE_LONG
Implements a Parser that converts a String to a Long.

See Also:
Long.valueOf(String)

PARSE_SHORT

public static final FlatFile.Parser PARSE_SHORT
Implements a Parser that converts a String to a Short.

See Also:
Short.valueOf(String)
Constructor Detail

FlatFile

public FlatFile(BufferedReader reader)
         throws IOException
Creates a FlatFile with the CSV tokenizer. The CSV Tokenizer is for reading comma separated value files.

Parameters:
reader - is the stream to be read.

FlatFile

public FlatFile(BufferedReader reader,
                Tokenizer tokenizer)
         throws IOException
Creates a FlatFile from a BufferedReader.

Parameters:
reader - is the stream to be read.
tokenizer - splits a text line into tokens, one per column.

FlatFile

public FlatFile(String filename)
         throws IOException
Creates a FlatFile from a CSV file. A CSV file is a comma separated value file.

Parameters:
filename - is the name of the file to be read.

FlatFile

public FlatFile(String filename,
                Tokenizer tokenizer)
         throws IOException
Creates a FlatFile from a file with the default tokenizer.

Parameters:
filename - is the name of the file to be read.
tokenizer - is the Tokenizer used to split lines into token strings.
Method Detail

doGetBytes

protected byte[] doGetBytes(int columnIndex)
                     throws SQLException
Gets the value of the designated column in the current row as a byte array.

Specified by:
doGetBytes in class AbstractFlatFile
Parameters:
columnIndex - the first column is 1, the second is 2, ...
Returns:
the column value; if the value is SQL NULL, the value returned is null
Throws:
SQLException - if a database access error occurs

doNext

protected boolean doNext()
                  throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.

Specified by:
doNext in class AbstractFlatFile
Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs

getColumnCount

public int getColumnCount()
                   throws SQLException
Returns the number of columns in this ResultSet object.

Specified by:
getColumnCount in class AbstractFlatFile
Returns:
the number of columns
Throws:
SQLException - if a database access error occurs

getObject

public Object getObject(int columnIndex)
                 throws SQLException

Gets the value of the designated column in the current row of this ResultSet object as an Object in the Java programming language.

This method will return the value of the given column as a Java object. The type of the Java object will be the default Java object type corresponding to the column's SQL type, following the mapping for built-in types specified in the JDBC specification.

This method may also be used to read datatabase-specific abstract data types. In the JDBC 2.0 API, the behavior of method getObject is extended to materialize data of SQL user-defined types. When a column contains a structured or distinct value, the behavior of this method is as if it were a call to: getObject(columnIndex, this.getStatement().getConnection().getTypeMap()).

Specified by:
getObject in interface ResultSet
Specified by:
getObject in class AbstractFlatFile
Parameters:
columnIndex - the first column is 1, the second is 2, ...
Returns:
a java.lang.Object holding the column value
Throws:
SQLException - if a database access error occurs

readLine

protected String readLine()
                   throws IOException
Reads and returns a line from the input.

Throws:
IOException

setColumnClass

protected void setColumnClass(int columnIndex,
                              Class columnClass)
Description copied from class: AbstractFlatFile
Sets a column class.

Overrides:
setColumnClass in class AbstractFlatFile
Parameters:
columnIndex - an int specifying the index of a column
columnClass - a Class object used to specify the class of the data in the column

setColumnParser

protected void setColumnParser(int columnIndex,
                               FlatFile.Parser columnParser)
Sets the Parser for the specified column.

Parameters:
columnIndex - the column index of the column
columnParser - is the Parser to be used to parse entries in the specified column.

setDateColumnParser

protected void setDateColumnParser(int columnIndex,
                                   String pattern,
                                   Locale locale)
Creates for a pattern string and sets the Parser for the specified column.

Parameters:
pattern - is used to construct a java.text.SimpleDateFormat object used to parse the column.
locale - is the Locale for the date format Parser.

JMSLTM Numerical Library 4.0

Copyright 1970-2006 Visual Numerics, Inc.
Built June 1 2006.