public class DbaseFileReader extends Object implements FileReader
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 |
Modifier and Type | Field and Description |
---|---|
protected long |
currentOffset |
protected boolean |
randomAccessEnabled |
protected boolean |
useMemoryMappedBuffer |
Constructor and Description |
---|
DbaseFileReader(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
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Clean up all resources associated with this reader.
|
protected int |
fill(ByteBuffer buffer,
ReadableByteChannel channel) |
DbaseFileHeader |
getHeader()
Get the header from this file.
|
boolean |
hasNext()
Query the reader as to whether there is another record.
|
String |
id()
An id for the reader.
|
static void |
main(String[] args) |
void |
read()
Reads the next record into memory.
|
Object[] |
readEntry()
Get the next record (entry).
|
Object[] |
readEntry(Object[] entry)
Copy the next entry into the array.
|
Object[] |
readEntry(Object[] entry,
int offset)
Copy the next record into the array starting at offset.
|
Object |
readField(int fieldNum)
Reads a single field from the current record and returns it.
|
DbaseFileReader.Row |
readRow() |
void |
skip()
Skip the next record.
|
void |
transferTo(DbaseFileWriter writer)
Transfer, by bytes, the next record to the writer.
|
protected boolean useMemoryMappedBuffer
protected boolean randomAccessEnabled
protected long currentOffset
public DbaseFileReader(ShpFiles shapefileFiles, boolean useMemoryMappedBuffer, Charset charset, TimeZone timeZone) throws IOException
shapefileFiles.
- The readable channel to use.IOException
- If an error occurs while initializing.public DbaseFileReader(ShpFiles shapefileFiles, boolean useMemoryMappedBuffer, Charset charset) throws IOException
IOException
public DbaseFileReader(ReadableByteChannel readChannel, boolean useMemoryMappedBuffer, Charset charset) throws IOException
IOException
public DbaseFileReader(ReadableByteChannel readChannel, boolean useMemoryMappedBuffer, Charset charset, TimeZone timeZone) throws IOException
IOException
protected int fill(ByteBuffer buffer, ReadableByteChannel channel) throws IOException
IOException
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 DbaseFileReader.Row readRow() throws IOException
IOException
public void skip() throws IOException
IOException
- If an error occurs.public Object[] readEntry(Object[] entry, int offset) throws IOException
entry
- Th array to copy into.offset
- The offset to start atIOException
- If an error occurs.public Object readField(int fieldNum) throws IOException
read()
before starting to read fields from the dbf, and call it every time you need to move to the
next record.fieldNum
- The field number to be read (zero based)IOException
- If an error occurs.public void transferTo(DbaseFileWriter writer) throws IOException
IOException
public void read() throws IOException
readField(int)
.IOException
public Object[] readEntry(Object[] entry) throws IOException
entry
- The array to copy into.IOException
- If an error occurs.public String id()
FileReader
id
in interface FileReader
Copyright © 1996–2019 Geotools. All rights reserved.