|
JMSLTM Numerical Library 5.0.1 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.imsl.io.AbstractFlatFile com.imsl.io.FlatFile
public class FlatFile
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(boolean)
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.
Nested Class Summary | |
---|---|
static interface |
FlatFile.Parser
Defines a method that parses a String into an Object. |
Nested classes/interfaces 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 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 |
---|
public static final FlatFile.Parser PARSE_BYTE
Byte.valueOf(String)
public static final FlatFile.Parser PARSE_DOUBLE
Double.valueOf(String)
public static final FlatFile.Parser PARSE_FLOAT
Float.valueOf(String)
public static final FlatFile.Parser PARSE_INTEGER
Integer.valueOf(String)
public static final FlatFile.Parser PARSE_LONG
Long.valueOf(String)
public static final FlatFile.Parser PARSE_SHORT
Short.valueOf(String)
Constructor Detail |
---|
public FlatFile(BufferedReader reader) throws IOException
reader
- is the stream to be read.
IOException
public FlatFile(BufferedReader reader, Tokenizer tokenizer) throws IOException
reader
- is the stream to be read.tokenizer
- splits a text line into tokens, one per column.
IOException
public FlatFile(String filename) throws IOException
filename
- is the name of the file to be read.
IOException
public FlatFile(String filename, Tokenizer tokenizer) throws IOException
filename
- is the name of the file to be read.tokenizer
- is the Tokenizer used to split lines into token strings.
IOException
Method Detail |
---|
protected byte[] doGetBytes(int columnIndex) throws SQLException
byte
array.
doGetBytes
in class AbstractFlatFile
columnIndex
- the first column is 1, the second is 2, ...
NULL
, the
value returned is null
SQLException
- if a database access error occursprotected boolean doNext() throws SQLException
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.
doNext
in class AbstractFlatFile
true
if the new current row is valid;
false
if there are no more rows
SQLException
- if a database access error occurspublic int getColumnCount() throws SQLException
ResultSet
object.
getColumnCount
in class AbstractFlatFile
SQLException
- if a database access error occurspublic 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())
.
getObject
in interface ResultSet
getObject
in class AbstractFlatFile
columnIndex
- the first column is 1, the second is 2, ...
java.lang.Object
holding the column value
SQLException
- if a database access error occursprotected String readLine() throws IOException
IOException
protected void setColumnClass(int columnIndex, Class columnClass)
AbstractFlatFile
setColumnClass
in class AbstractFlatFile
columnIndex
- an int
specifying the index of a columncolumnClass
- a Class
object used to specify the
class of the data in the columnprotected void setColumnParser(int columnIndex, FlatFile.Parser columnParser)
columnIndex
- the column index of the columncolumnParser
- is the Parser to be used to parse entries in the specified column.protected void setDateColumnParser(int columnIndex, String pattern, Locale locale)
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 5.0.1 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |