|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jwo.utils.dbase.DbaseFileReader
public class DbaseFileReader
Used to read Dbase III files. This code is based
on the class provided as part of the Geotools OpenSource mapping
toolkit - http://www.geotools.org/
under the GNU Lesser General Public License.
The general use of this class is:
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 )
Object[] fields = new Object[r.getHeader().getNumFields()];
while (r.hasNext())
{
r.readEntry(fields);
// do stuff
}
r.close();
EACH CALL TO readEntry OR readRow ADVANCES THE FILE!
An example of using the Row method of reading:
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();
Nested Class Summary | |
---|---|
class |
DbaseFileReader.Row
Stores an individual row in the database. |
Constructor Summary | |
---|---|
DbaseFileReader(ReadableByteChannel channel)
Creates a new instance of DBaseFileReader. |
|
DbaseFileReader(ReadableByteChannel channel,
Logger logger)
Creates a new instance of DBaseFileReader with warning messages reported to the given logger. |
Method Summary | |
---|---|
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. |
Object[] |
readEntry()
Retrieves the next record (entry). |
Object[] |
readEntry(Object[] entry,
boolean doSimple)
Copies the next entry into the array. |
Object[] |
readEntry(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. |
Object[] |
readSimpleEntry()
Retrieves the next record (entry), formatted as a collection of numbers and/or strings. |
void |
skip()
Skips the next record. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DbaseFileReader(ReadableByteChannel channel) throws IOException
channel
- The readable channel to use.
IOException
- If an error occurs while initializing.public DbaseFileReader(ReadableByteChannel channel, Logger logger) throws IOException
channel
- The readable channel to use.logger
- Logger to monitor warning messages.
IOException
- If an error occurs while initializing.Method Detail |
---|
public DbaseFileHeader getHeader()
public void close() throws IOException
IOException
- If an error occurs.public boolean hasNext()
public Object[] readEntry() throws IOException
IOException
- If an error occurs.public Object[] readSimpleEntry() throws IOException
IOException
- If an error occurs.public DbaseFileReader.Row readRow() throws IOException
IOException
- if error occurs when reading.public void skip() throws IOException
IOException
- if an error occurs.public Object[] readEntry(Object[] entry, int offset, boolean doSimple) throws IOException
entry
- The array to copy into.offset
- The offset to start at.doSimple
- Will format as strings/numbers if true.
IOException
- id an error occurs.public Object[] readEntry(Object[] entry, boolean doSimple) throws IOException
entry
- The array to copy into.doSimple
- Will format as strings/numbers if true.
IOException
- If an error occurs when trying to read entry from database.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |