|
DataFile 1.4 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.infomata.data.DataFile
Main class for generating or reading data files written in widely accepted
data format. Currently supported data formats are tab separate (TabFormat)
and CSV (CSVFormat), but more data formats can
easily be added by implementing DataFormat
USAGE:
// Creating a reader for CSV file using ISO-8859-1
DataFile read = DataFile.createReader("8859_1");
read.setDataFormat(new CSVFormat());
try
{
read.open(new File("/data/test.csv"));
for (DataRow row = read.next(); row != null; row = read.next())
{
String text = row.getString(0);
int number1 = row.getInt(1, 0);
double number2 = row.getDouble(2);
// use the retrieved data ...
}
}
finally
{
read.close();
}
// Creating a writer for data file with European encoding
// ISO-8859-2 (European) using tab separated format.
// (rewrite existing file)
DataFile write = DataFile.createWriter("8859_2", false);
write.setDataFormat(new TabFormat());
try
{
write.open(new File("/data/test.txt"));
for (DataRow row = write.next(); row != null; row = write.next())
{
row.add("some German text");
row.add(123);
row.add(13323.23d);
}
}
finally
{
write.close();
}
| Method Summary | |
void |
close()
Closes a data file. |
boolean |
containsHeader()
Checks if header indicator has been turned on using containsHeader(boolean). |
void |
containsHeader(boolean header)
Sets the indicator for header row (must be first line of data file). |
static DataFile |
createReader(java.lang.String enc)
Creates a reader instance of a data file. |
static DataFile |
createWriter(java.lang.String enc,
boolean append)
Creates a writer instance of DataFile used for writing a data file. |
void |
finalize()
Finalization method that closes the file descriptor. |
java.util.List |
getHeaderList()
Retrieves the list of header names found in the first row of the data file in the sequence they appear. |
java.util.Iterator |
getHeaderNames()
Deprecated. use getHeaderList() instead. |
DataRow |
next()
Retrieves the next row for reading or writing data |
void |
open(java.io.File file)
Opens a data file for reading or writing |
void |
open(java.net.URL file)
|
void |
setDataFormat(DataFormat format)
Sets the data format to be read or written. |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static final DataFile createReader(java.lang.String enc)
enc - Java character encoding in which the data file is written.
public static final DataFile createWriter(java.lang.String enc,
boolean append)
enc - Java encoding to use while writing the data file containing
none-English characters.append - True if appending to existing data file. False, if writing to
a new file or overwriting current file.
public final void containsHeader(boolean header)
header - True if the file contains a header row. False, otherwise.public final boolean containsHeader()
containsHeader(boolean). Data file reader lacks the logic to
determine if the first row is a header row, automatically, so the
existance of header row must be indicated prior to reading the data file.
true.
False, otherwise.public final void setDataFormat(DataFormat format)
format - an instance of a class that implements DataFormat interface.DataFormatpublic void finalize()
public final void close()
public final void open(java.io.File file)
throws java.io.IOException
file - data file
java.io.IOException - if an error occurs
public final void open(java.net.URL file)
throws java.io.IOException
java.io.IOException
public final DataRow next()
throws java.io.IOException
java.io.IOException - if an error occurspublic final java.util.Iterator getHeaderNames()
getHeaderList() instead.
public final java.util.List getHeaderList()
|
DataFile 1.4 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||