de.fhg.igd.earth.model.input.shapefile
Class DBaseFile

java.lang.Object
  extended byde.fhg.igd.earth.model.input.shapefile.ShapeUtils
      extended byde.fhg.igd.earth.model.input.shapefile.DBaseFile

public class DBaseFile
extends ShapeUtils

Class representing a DBase File. Title : Earth Copyright : Copyright (c) 2001 Organisation : IGD FhG

Version:
: 1.0
Author:
: Werner Beutel

Field Summary
static int DEFAULT_RECORD_BUFFER_SIZE_DB
          A default DBase record size.
protected  int[] fieldLength
          A field that holds the length of the DBase fields, in bytes.
protected  String[] fieldName
          A field that holds the names of the DBase fields, as a string.
protected  char[] fieldType
          A field that holds the types of the DBase fields, as a char.
protected  long fileLength
          Holds the length of the DBase file, in bytes.
protected  byte[] header
          The buffer that holds header of the DBase file.
protected  int headerLength
          Holds the length of the DBase file header.
protected  boolean io
          A flag for the IO mode true=read/write false=read.
protected  RandomAccessFile raf
          The read/write class for shape DBase files.
protected  byte[] recBuf
          A buffer for the current DBase record's data.
protected  int recordLength
          Holds the record length of the DBase file, as an int.
protected  int recordNumbers
          Holds the numbers of the records, in bytes.
protected  int rows
          Holds the numbers of the row of the DBase file, as an int.
 
Fields inherited from class de.fhg.igd.earth.model.input.shapefile.ShapeUtils
SHAPE_FILE_HEADER_LENGTH, SHAPE_FILE_HEADER_LENGTH_DB, SHAPE_FILE_RECORD_HEADER_LENGTH, SHAPE_TYPE_ARC, SHAPE_TYPE_MULTIPOINT, SHAPE_TYPE_NULL, SHAPE_TYPE_POINT, SHAPE_TYPE_POLYGON, SHAPE_TYPE_POLYLINE
 
Constructor Summary
DBaseFile(String name)
          Construct a DBaseFile from a file name.
 
Method Summary
 void addRecord(DBaseFile dbf)
          Adds a record to the end of this file.
 void close()
          Closes the DBase file and disposes of resources.
 String getFieldData(int index)
          Returns the field data of the table at the current position
 String getFieldName(int index)
          Returns the field name of the DBase table
 char getFieldType(int index)
          Returns the field type of the table
 int getNextRecord()
          Reads the next record from the DBase file Each successive call gets the next record.
protected  void initHeader()
          Reads or initialises the header of a DBase file.
 int numRows()
          Returns the number of rows of the DBase table
protected  void readHeader()
          Reads and parses the header of the file.
 void writeHeader(DBaseFile dbf)
          Writes a header into an empty DBase file A prototype header of another DBase file is needed
 
Methods inherited from class de.fhg.igd.earth.model.input.shapefile.ShapeUtils
readBEInt, readBox, readLEDouble, readLEInt, readLEInt, readLELong, readPoint, writeBEInt, writeBox, writeLEDouble, writeLEInt, writeLELong, writePoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RECORD_BUFFER_SIZE_DB

public static final int DEFAULT_RECORD_BUFFER_SIZE_DB
A default DBase record size. Automatically increased on demand.

See Also:
Constant Field Values

raf

protected RandomAccessFile raf
The read/write class for shape DBase files.


header

protected byte[] header
The buffer that holds header of the DBase file.


headerLength

protected int headerLength
Holds the length of the DBase file header.


fileLength

protected long fileLength
Holds the length of the DBase file, in bytes.


recordNumbers

protected int recordNumbers
Holds the numbers of the records, in bytes.


rows

protected int rows
Holds the numbers of the row of the DBase file, as an int.


recordLength

protected int recordLength
Holds the record length of the DBase file, as an int.


recBuf

protected byte[] recBuf
A buffer for the current DBase record's data.


io

protected boolean io
A flag for the IO mode true=read/write false=read.


fieldName

protected String[] fieldName
A field that holds the names of the DBase fields, as a string.


fieldLength

protected int[] fieldLength
A field that holds the length of the DBase fields, in bytes.


fieldType

protected char[] fieldType
A field that holds the types of the DBase fields, as a char.

Constructor Detail

DBaseFile

public DBaseFile(String name)
          throws IOException
Construct a DBaseFile from a file name.

Throws:
IOException - if something goes wrong opening or reading the file.
Method Detail

initHeader

protected void initHeader()
                   throws IOException
Reads or initialises the header of a DBase file. If the file is not empty, the header is read.

After this function runs, the file pointer is set to the first byte of the first record in the file.

Throws:
IOException - if something goes wrong reading or writing the DBase file

writeHeader

public void writeHeader(DBaseFile dbf)
                 throws IOException
Writes a header into an empty DBase file A prototype header of another DBase file is needed

Throws:
IOException - if something goes wrong reading the file

readHeader

protected void readHeader()
                   throws IOException
Reads and parses the header of the file. Values from the header are stored in the fields of this class.

Throws:
IOException - if something goes wrong reading the file

numRows

public int numRows()
Returns the number of rows of the DBase table


getFieldName

public String getFieldName(int index)
Returns the field name of the DBase table

Throws:
IOException - if something goes wrong reading the file

getFieldData

public String getFieldData(int index)
Returns the field data of the table at the current position

Throws:
IOException - if something goes wrong reading the file

getFieldType

public char getFieldType(int index)
Returns the field type of the table

Throws:
IOException - if something goes wrong reading the file

getNextRecord

public int getNextRecord()
                  throws IOException
Reads the next record from the DBase file Each successive call gets the next record. There is no way to go back a record. When there are no more records, null is returned.

Returns:
a record length, or 0 if there are no more records
Throws:
IOException - if something goes wrong reading the file

addRecord

public void addRecord(DBaseFile dbf)
               throws IOException
Adds a record to the end of this file. The record is written to the file at the end of the last record.

Throws:
IOException - if something goes wrong writing to the file

close

public void close()
           throws IOException
Closes the DBase file and disposes of resources.

Throws:
IOException - if something goes wrong closing the file


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.