Package org.geotools.data.shapefile.dbf
Class DbaseFileReader
Object
DbaseFileReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,FileReader
- Direct Known Subclasses:
IndexedDbaseFileReader
A DbaseFileReader is used to read a dbase III format file.
The general use of this class is:
EACH CALL TO readEntry OR readRow ADVANCES THE FILE!
An example of using the Row method of reading:
The general use of this class is:
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). 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();
- Author:
- Ian Schneider, Andrea Aaime
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
protected boolean
protected boolean
-
Constructor Summary
ConstructorsConstructorDescriptionDbaseFileReader
(ReadableByteChannel readChannel, boolean useMemoryMappedBuffer, Charset charset) DbaseFileReader
(ReadableByteChannel readChannel, boolean useMemoryMappedBuffer, Charset charset, TimeZone timeZone) DbaseFileReader
(ShpFiles shapefileFiles, boolean useMemoryMappedBuffer, Charset charset) DbaseFileReader
(ShpFiles shapefileFiles, boolean useMemoryMappedBuffer, Charset charset, TimeZone timeZone) Creates a new instance of DBaseFileReader -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Clean up all resources associated with this reader.Highly recomended.protected int
fill
(ByteBuffer buffer, ReadableByteChannel channel) Get the header from this file.boolean
hasNext()
Query the reader as to whether there is another record.id()
An id for the reader.static void
void
read()
Reads the next record into memory.Object[]
Get the next record (entry).Object[]
Copy the next entry into the array.Object[]
Copy the next record into the array starting at offset.readField
(int fieldNum) Reads a single field from the current record and returns it.readRow()
void
skip()
Skip the next record.void
transferTo
(DbaseFileWriter writer) Transfer, by bytes, the next record to the writer.
-
Field Details
-
useMemoryMappedBuffer
protected boolean useMemoryMappedBuffer -
randomAccessEnabled
protected boolean randomAccessEnabled -
currentOffset
protected long currentOffset
-
-
Constructor Details
-
DbaseFileReader
public DbaseFileReader(ShpFiles shapefileFiles, boolean useMemoryMappedBuffer, Charset charset, TimeZone timeZone) throws IOException Creates a new instance of DBaseFileReader- Parameters:
shapefileFiles
- The readable channel to use.- Throws:
IOException
- If an error occurs while initializing.
-
DbaseFileReader
public DbaseFileReader(ShpFiles shapefileFiles, boolean useMemoryMappedBuffer, Charset charset) throws IOException - Throws:
IOException
-
DbaseFileReader
public DbaseFileReader(ReadableByteChannel readChannel, boolean useMemoryMappedBuffer, Charset charset) throws IOException - Throws:
IOException
-
DbaseFileReader
public DbaseFileReader(ReadableByteChannel readChannel, boolean useMemoryMappedBuffer, Charset charset, TimeZone timeZone) throws IOException - Throws:
IOException
-
-
Method Details
-
fill
- Throws:
IOException
-
getHeader
Get the header from this file. The header is read upon instantiation.- Returns:
- The header associated with this file or null if an error occurred.
-
close
Clean up all resources associated with this reader.Highly recomended.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an error occurs.
-
hasNext
public boolean hasNext()Query the reader as to whether there is another record.- Returns:
- True if more records exist, false otherwise.
-
readEntry
Get the next record (entry). Will return a new array of values.- Returns:
- A new array of values.
- Throws:
IOException
- If an error occurs.
-
readRow
- Throws:
IOException
-
skip
Skip the next record.- Throws:
IOException
- If an error occurs.
-
readEntry
Copy the next record into the array starting at offset.- Parameters:
entry
- Th array to copy into.offset
- The offset to start at- Returns:
- The same array passed in.
- Throws:
IOException
- If an error occurs.
-
readField
Reads a single field from the current record and returns it. Remember to callread()
before starting to read fields from the dbf, and call it every time you need to move to the next record.- Parameters:
fieldNum
- The field number to be read (zero based)- Returns:
- The value of the field
- Throws:
IOException
- If an error occurs.
-
transferTo
Transfer, by bytes, the next record to the writer.- Throws:
IOException
-
read
Reads the next record into memory. You need to use this directly when reading only a subset of the fields usingreadField(int)
.- Throws:
IOException
-
readEntry
Copy the next entry into the array.- Parameters:
entry
- The array to copy into.- Returns:
- The same array passed in.
- Throws:
IOException
- If an error occurs.
-
main
- Throws:
Exception
-
id
Description copied from interface:FileReader
An id for the reader. This is only used for debugging.- Specified by:
id
in interfaceFileReader
- Returns:
- id for the reader.
-