org.deegree_impl.io.shpapi
Class DBaseFile

java.lang.Object
  extended byorg.deegree_impl.io.shpapi.DBaseFile

public class DBaseFile
extends java.lang.Object

the datatypes of the dBase file and their representation as java types: dBase-type dBase-type-ID java-type character "C" String float "F" Float number "N" Double logical "L" String memo "M" String date "D" Date binary "B" ByteArrayOutputStream

Version:
12.12.2000
Author:
Andreas Poth, Markus Müller, email: mm@giub.uni-bonn.de

Field Summary
private  java.lang.String _dbf
           
private  long cacheSize
           
private  java.util.ArrayList colHeader
           
private  java.util.Hashtable column_info
           
private  byte[] dataArray
           
private  DBFDataSection dataSection
           
private  boolean eof
           
private  FeatureType featureType
           
private  int file_datalength
           
private  int file_datap
           
private  double file_numrecs
           
private  short file_type
           
private  short file_update_day
           
private  short file_update_month
           
private  short file_update_year
           
private  int filemode
           
private  java.lang.String fname
           
private  java.lang.String ftName
           
private  DBFHeader header
           
private  int num_fields
           
private  java.io.RandomAccessFile rafDbf
           
private  long record_number
           
private  long startIndex
           
 
Constructor Summary
DBaseFile(java.lang.String url)
          constructor
only for reading a dBase file
DBaseFile(java.lang.String url, FieldDescriptor[] fieldDesc)
          constructor
only for writing a dBase file
 
Method Summary
 void close()
           
private  boolean contains(java.lang.String[] container, java.lang.String element)
          method: private boolean contains(String[] container, String element)
retruns true if the container sting array contains element
private  FeatureType createFeatureType()
           
private static short fixByte(byte b)
          method: private fixByte (byte b)
bytes are signed; let's fix them...
 java.lang.String getColumn(java.lang.String col_name)
          method: getColumn(String col_name)
Retrieve a column's string value from the current row.
 int getDataLength(java.lang.String field)
          returns the size of a column
 java.lang.String[] getDataTypes()
          method: public String[] getDataTypes()
returns the datatype of each column of the database
 java.lang.String[] getDataTypes(java.lang.String[] fields)
          method: public String[] getDataTypes(String[] fields)
returns the datatype of each column of the database specified by fields
 Feature getFRow(int rowNo)
          returns a row of the dBase-file as Feature containing a place holder (field name = "GEOM") for a geometry.
 java.lang.String[] getProperties()
          method: public String[] getProperties()
returns the properties (column headers) of the dBase-file
 int getRecordNum()
          method: getRecordNum()
Get the number of records in the table
 java.lang.Object[] getRow(int rowNo)
          method: public ArrayList getRow(int row)
returns a row of the dBase-file
 void goTop()
          method: goTop()
Position the record pointer at the top of the table.
private  void initDBaseFile()
          method: initDBaseFile(); inits a DBF file.
 boolean nextRecord()
          method: nextRecord()
Advance the record pointer to the next record.
 void setRecord(java.util.ArrayList recData)
          method: public setRecord(ArrayList recData) writes a data record to byte array representing the data section of the dBase file.
 void setRecord(int index, java.util.ArrayList recData)
          method: public setRecord(int index, ArrayList recData) writes a data record to byte array representing the data section of the dBase file.
 void writeAllToFile()
          method: public void writeAllToFile() creates the dbase file and writes all data to it if the file specified by fname (s.o.) exists it will be deleted!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colHeader

private java.util.ArrayList colHeader

dataSection

private DBFDataSection dataSection

featureType

private FeatureType featureType

column_info

private java.util.Hashtable column_info

rafDbf

private java.io.RandomAccessFile rafDbf

_dbf

private final java.lang.String _dbf
See Also:
Constant Field Values

header

private DBFHeader header

fname

private java.lang.String fname

ftName

private java.lang.String ftName

eof

private boolean eof

file_numrecs

private double file_numrecs

file_datalength

private int file_datalength

file_datap

private int file_datap

filemode

private int filemode

num_fields

private int num_fields

record_number

private long record_number

file_type

private short file_type

file_update_day

private short file_update_day

file_update_month

private short file_update_month

file_update_year

private short file_update_year

cacheSize

private long cacheSize

dataArray

private byte[] dataArray

startIndex

private long startIndex
Constructor Detail

DBaseFile

public DBaseFile(java.lang.String url)
          throws java.io.IOException
constructor
only for reading a dBase file


DBaseFile

public DBaseFile(java.lang.String url,
                 FieldDescriptor[] fieldDesc)
          throws DBaseException
constructor
only for writing a dBase file

Method Detail

close

public void close()

initDBaseFile

private void initDBaseFile()
                    throws java.io.IOException
method: initDBaseFile(); inits a DBF file. This is based on Pratap Pereira's Xbase.pm perl module

Throws:
java.io.IOException

createFeatureType

private FeatureType createFeatureType()
Returns:

getRecordNum

public int getRecordNum()
                 throws DBaseException
method: getRecordNum()
Get the number of records in the table

Throws:
DBaseException

goTop

public void goTop()
           throws DBaseException
method: goTop()
Position the record pointer at the top of the table.

Throws:
DBaseException

nextRecord

public boolean nextRecord()
                   throws DBaseException
method: nextRecord()
Advance the record pointer to the next record.

Throws:
DBaseException

getColumn

public java.lang.String getColumn(java.lang.String col_name)
                           throws DBaseException
method: getColumn(String col_name)
Retrieve a column's string value from the current row.

Throws:
DBaseException

getProperties

public java.lang.String[] getProperties()
                                 throws DBaseException
method: public String[] getProperties()
returns the properties (column headers) of the dBase-file

Throws:
DBaseException

getDataTypes

public java.lang.String[] getDataTypes()
                                throws DBaseException
method: public String[] getDataTypes()
returns the datatype of each column of the database

Throws:
DBaseException

contains

private boolean contains(java.lang.String[] container,
                         java.lang.String element)
method: private boolean contains(String[] container, String element)
retruns true if the container sting array contains element


getDataLength

public int getDataLength(java.lang.String field)
                  throws DBaseException
returns the size of a column

Throws:
DBaseException

getDataTypes

public java.lang.String[] getDataTypes(java.lang.String[] fields)
                                throws DBaseException
method: public String[] getDataTypes(String[] fields)
returns the datatype of each column of the database specified by fields

Throws:
DBaseException

getFRow

public Feature getFRow(int rowNo)
                throws DBaseException
returns a row of the dBase-file as Feature containing a place holder (field name = "GEOM") for a geometry.

Throws:
DBaseException

getRow

public java.lang.Object[] getRow(int rowNo)
                          throws DBaseException
method: public ArrayList getRow(int row)
returns a row of the dBase-file

Throws:
DBaseException

fixByte

private static short fixByte(byte b)
method: private fixByte (byte b)
bytes are signed; let's fix them...


writeAllToFile

public void writeAllToFile()
                    throws java.io.IOException,
                           DBaseException
method: public void writeAllToFile() creates the dbase file and writes all data to it if the file specified by fname (s.o.) exists it will be deleted!

Throws:
java.io.IOException
DBaseException

setRecord

public void setRecord(java.util.ArrayList recData)
               throws DBaseException
method: public setRecord(ArrayList recData) writes a data record to byte array representing the data section of the dBase file. The method gets the data type of each field in recData from fieldDesc wich has been set at the constructor.

Throws:
DBaseException

setRecord

public void setRecord(int index,
                      java.util.ArrayList recData)
               throws DBaseException
method: public setRecord(int index, ArrayList recData) writes a data record to byte array representing the data section of the dBase file. The method gets the data type of each field in recData from fieldDesc wich has been set at the constructor. index specifies the location of the retrieved record in the datasection. if an invalid index is used an exception will be thrown

Throws:
DBaseException