|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileReaderNIO
A DbaseFileReader is used to read a dbase III format file.
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 |
DbaseFileReaderNIO.Row
|
Constructor Summary | |
DbaseFileReaderNIO(java.nio.channels.ReadableByteChannel channel)
Creates a new instance of DBaseFileReader |
Method Summary | |
void |
close()
Clean up all resources associated with this reader. |
DbaseFileHeaderNIO |
getHeader()
Get the header from this file. |
boolean |
hasNext()
Query the reader as to whether there is another record. |
static void |
main(java.lang.String[] args)
|
java.lang.Object[] |
readEntry()
Get the next record (entry). |
java.lang.Object[] |
readEntry(java.lang.Object[] entry)
Copy the next entry into the array. |
java.lang.Object[] |
readEntry(java.lang.Object[] entry,
int offset)
Copy the next record into the array starting at offset. |
DbaseFileReaderNIO.Row |
readRow()
|
void |
skip()
Skip the next record. |
void |
transferTo(DbaseFileWriterNIO writer)
Transfer, by bytes, the next record to the writer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DbaseFileReaderNIO(java.nio.channels.ReadableByteChannel channel) throws java.io.IOException
channel
- The readable channel to use.
java.io.IOException
- If an error occurs while initializing.Method Detail |
public DbaseFileHeaderNIO 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 DbaseFileReaderNIO.Row readRow() throws java.io.IOException
java.io.IOException
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) throws java.io.IOException
entry
- Th array to copy into.offset
- The offset to start at
java.io.IOException
- If an error occurs.public void transferTo(DbaseFileWriterNIO writer) throws java.io.IOException
java.io.IOException
public java.lang.Object[] readEntry(java.lang.Object[] entry) throws java.io.IOException
entry
- The array to copy into.
java.io.IOException
- If an error occurs.public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |