public class DbaseFileReader
extends java.lang.Object
FileChannel in = new FileInputStream("thefile.dbf").getChannel(); DbaseFileReader r = new DbaseFileReader( in ) Object[] fields = new Object[r.getHeader().getNumFields()]; while (r.hasNext()) { r.readEntry(fields); // do stuff } r.close();For consumers who wish to be a bit more selective with their reading of rows, the Row object has been added. The semantics are the same as using the readEntry method, but remember that the Row object is always the same. The values are parsed as they are read, so it pays to copy them out (as each call to Row.read() will result in an expensive String parse).
FileChannel in = new FileInputStream("thefile.dbf").getChannel(); DbaseFileReader r = new DbaseFileReader(in) int fields = r.getHeader().getNumFields(); while (r.hasNext()) { DbaseFileReader.Row row = r.readRow(); for (int i = 0; i < fields; i++) { // do stuff Foo.bar(row.read(i)); } } r.close();
Modifier and Type | Class and Description |
---|---|
class |
DbaseFileReader.Row
Stores an individual row in the database.
|
Constructor and Description |
---|
DbaseFileReader(java.nio.channels.ReadableByteChannel channel)
Creates a new instance of DBaseFileReader.
|
DbaseFileReader(java.nio.channels.ReadableByteChannel channel,
java.util.logging.Logger logger)
Creates a new instance of DBaseFileReader with warning messages reported
to the given logger.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Cleans up all resources associated with this reader.
|
DbaseFileHeader |
getHeader()
Retrieves the header from this file.
|
boolean |
hasNext()
Queries the reader as to whether there is another record.
|
java.lang.Object[] |
readEntry()
Retrieves the next record (entry).
|
java.lang.Object[] |
readEntry(java.lang.Object[] entry,
boolean doSimple)
Copies the next entry into the array.
|
java.lang.Object[] |
readEntry(java.lang.Object[] entry,
int offset,
boolean doSimple)
Copies the next record into the array starting at offset.
|
DbaseFileReader.Row |
readRow()
Reads the next row from the database.
|
java.lang.Object[] |
readSimpleEntry()
Retrieves the next record (entry), formatted as a collection of numbers
and/or strings.
|
void |
skip()
Skips the next record.
|
public DbaseFileReader(java.nio.channels.ReadableByteChannel channel) throws java.io.IOException
channel
- The readable channel to use.java.io.IOException
- If an error occurs while initializing.public DbaseFileReader(java.nio.channels.ReadableByteChannel channel, java.util.logging.Logger logger) throws java.io.IOException
channel
- The readable channel to use.logger
- Logger to monitor warning messages.java.io.IOException
- If an error occurs while initializing.public DbaseFileHeader getHeader()
public void close() throws java.io.IOException
java.io.IOException
- If an error occurs.public boolean hasNext()
public java.lang.Object[] readEntry() throws java.io.IOException
java.io.IOException
- If an error occurs.public java.lang.Object[] readSimpleEntry() throws java.io.IOException
java.io.IOException
- If an error occurs.public DbaseFileReader.Row readRow() throws java.io.IOException
java.io.IOException
- if error occurs when reading.public void skip() throws java.io.IOException
java.io.IOException
- if an error occurs.public java.lang.Object[] readEntry(java.lang.Object[] entry, int offset, boolean doSimple) throws java.io.IOException
entry
- The array to copy into.offset
- The offset to start at.doSimple
- Will format as strings/numbers if true.java.io.IOException
- id an error occurs.public java.lang.Object[] readEntry(java.lang.Object[] entry, boolean doSimple) throws java.io.IOException
entry
- The array to copy into.doSimple
- Will format as strings/numbers if true.java.io.IOException
- If an error occurs when trying to read entry from database.