org.geotools.dbffile
Class DbfFile

java.lang.Object
  extended by org.geotools.dbffile.DbfFile

public class DbfFile
extends java.lang.Object

This class represents a DBF (or DBase) file.

Construct it with a filename (including the .dbf) this causes the header and field definitions to be read.

Later queries return rows or columns of the database.


Author:
Ian Turton Centre for Computaional Geography, University of Leeds, LS2 9JT, 1998.

Field Summary
static java.text.SimpleDateFormat DATE_PARSER
           
static int DBF_ALL_DELETED
           
static int DBF_BAD_DBFID
           
static int DBF_BAD_EODEFS
           
static int DBF_BAD_INT_WIDTH
           
static int DBF_BAD_ITYPE
           
static int DBF_BAD_OFFSET
           
static int DBF_BAD_SIZEOF
           
static int DBF_BUFFSIZE
           
static int DBF_CANNOT_DO_MEMO
           
static int DBF_CENTURY
           
static int DBF_END_OF_DEFS
           
static int DBF_FLOATING_N
           
static int DBF_GET_DATE
           
static int DBF_INT_EXP
           
static int DBF_INT_JUNK
           
static int DBF_INT_REAL
           
static int DBF_MALLOC
           
static int DBF_MALLOC_FIELD
           
static int DBF_MAXFIELDS
           
static int DBF_MAXLEN
           
static int DBF_NAMELEN
           
static int DBF_NO_FIELDS
           
static int DBF_OK
           
static int DBF_READ_DATA
           
static int DBF_READ_DEFS
           
static int DBF_READ_HEAD
           
static int DBF_REC_DELETED
           
static int DBF_REC_TOO_LONG
           
static int DBF_TOO_MANY_FIELDS
           
static int DBF_TOO_WIDE_FOR_INF
           
static int DBF_UNPRINT_DATA
           
static int DBF_WRITE_DATA
           
static int DBF_WRITE_DEFS
           
static int DBF_WRITE_HEAD
           
static int DBF3_MAXFIELDS
           
static int DBF4_MAXFIELDS
           
 EndianDataInputStream dFile
           
 DbfFieldDef[] fielddef
           
 
Constructor Summary
DbfFile(java.lang.String file)
          Constructor, opens the file and reads the header infomation.
 
Method Summary
 void close()
           
 java.lang.StringBuffer GetDbfRec(int row)
          fetches the rowth row of the file
 java.lang.String getFieldName(int row)
           
 java.lang.String getFieldType(int row)
           
 int getFileSize()
          Returns the size of the database file.
 java.lang.Double[] getFloatCol(int col)
          Fetches a column of Double from the database file.
 java.lang.Double[] getFloatCol(int col, int start, int end)
          Fetches a part column of Double from the database file.
 java.lang.Integer[] getIntegerCol(int col)
          Fetches a column of Integers from the database file.
 java.lang.Integer[] getIntegerCol(int col, int start, int end)
          Fetches a part column of Integers from the database file.
 int getLastRec()
          Returns the number of records in the database file.
 java.lang.String getLastUpdate()
          Returns the date of the last update of the file as a string.
 java.lang.StringBuffer GetNextDbfRec()
          gets the next record and returns it as a string.
 int getNumFields()
          Returns the number of fields in the records in the database file.
 int getRecSize()
          Returns the size of the records in the database file.
 java.lang.String[] getStringCol(int col)
          Fetches a column of Strings from the database file.
 java.lang.String[] getStringCol(int col, int start, int end)
          Fetches a part column of Strings from the database file.
static void main(java.lang.String[] args)
           
 java.util.Vector ParseDbfRecord(int row)
          fetches the rowth row of the file and parses it into an vector of objects.
 java.util.Vector ParseRecord(java.lang.StringBuffer rec)
          Parses the record stored in the StringBuffer rec into a vector of objects
 java.lang.Object ParseRecordColumn(java.lang.StringBuffer rec, int wantedCol)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dFile

public EndianDataInputStream dFile

fielddef

public DbfFieldDef[] fielddef

DATE_PARSER

public static final java.text.SimpleDateFormat DATE_PARSER

DBF_CENTURY

public static final int DBF_CENTURY
See Also:
Constant Field Values

DBF_MAXLEN

public static final int DBF_MAXLEN
See Also:
Constant Field Values

DBF_NAMELEN

public static final int DBF_NAMELEN
See Also:
Constant Field Values

DBF3_MAXFIELDS

public static final int DBF3_MAXFIELDS
See Also:
Constant Field Values

DBF4_MAXFIELDS

public static final int DBF4_MAXFIELDS
See Also:
Constant Field Values

DBF_MAXFIELDS

public static final int DBF_MAXFIELDS
See Also:
Constant Field Values

DBF_BUFFSIZE

public static final int DBF_BUFFSIZE
See Also:
Constant Field Values

DBF_END_OF_DEFS

public static final int DBF_END_OF_DEFS
See Also:
Constant Field Values

DBF_OK

public static final int DBF_OK
See Also:
Constant Field Values

DBF_READ_HEAD

public static final int DBF_READ_HEAD
See Also:
Constant Field Values

DBF_BAD_DBFID

public static final int DBF_BAD_DBFID
See Also:
Constant Field Values

DBF_WRITE_HEAD

public static final int DBF_WRITE_HEAD
See Also:
Constant Field Values

DBF_READ_DEFS

public static final int DBF_READ_DEFS
See Also:
Constant Field Values

DBF_TOO_MANY_FIELDS

public static final int DBF_TOO_MANY_FIELDS
See Also:
Constant Field Values

DBF_NO_FIELDS

public static final int DBF_NO_FIELDS
See Also:
Constant Field Values

DBF_BAD_EODEFS

public static final int DBF_BAD_EODEFS
See Also:
Constant Field Values

DBF_WRITE_DEFS

public static final int DBF_WRITE_DEFS
See Also:
Constant Field Values

DBF_BAD_ITYPE

public static final int DBF_BAD_ITYPE
See Also:
Constant Field Values

DBF_CANNOT_DO_MEMO

public static final int DBF_CANNOT_DO_MEMO
See Also:
Constant Field Values

DBF_BAD_INT_WIDTH

public static final int DBF_BAD_INT_WIDTH
See Also:
Constant Field Values

DBF_BAD_OFFSET

public static final int DBF_BAD_OFFSET
See Also:
Constant Field Values

DBF_FLOATING_N

public static final int DBF_FLOATING_N
See Also:
Constant Field Values

DBF_READ_DATA

public static final int DBF_READ_DATA
See Also:
Constant Field Values

DBF_UNPRINT_DATA

public static final int DBF_UNPRINT_DATA
See Also:
Constant Field Values

DBF_WRITE_DATA

public static final int DBF_WRITE_DATA
See Also:
Constant Field Values

DBF_INT_EXP

public static final int DBF_INT_EXP
See Also:
Constant Field Values

DBF_INT_REAL

public static final int DBF_INT_REAL
See Also:
Constant Field Values

DBF_INT_JUNK

public static final int DBF_INT_JUNK
See Also:
Constant Field Values

DBF_REC_DELETED

public static final int DBF_REC_DELETED
See Also:
Constant Field Values

DBF_ALL_DELETED

public static final int DBF_ALL_DELETED
See Also:
Constant Field Values

DBF_BAD_SIZEOF

public static final int DBF_BAD_SIZEOF
See Also:
Constant Field Values

DBF_REC_TOO_LONG

public static final int DBF_REC_TOO_LONG
See Also:
Constant Field Values

DBF_TOO_WIDE_FOR_INF

public static final int DBF_TOO_WIDE_FOR_INF
See Also:
Constant Field Values

DBF_MALLOC_FIELD

public static final int DBF_MALLOC_FIELD
See Also:
Constant Field Values

DBF_MALLOC

public static final int DBF_MALLOC
See Also:
Constant Field Values

DBF_GET_DATE

public static final int DBF_GET_DATE
See Also:
Constant Field Values
Constructor Detail

DbfFile

public DbfFile(java.lang.String file)
        throws java.io.IOException,
               DbfFileException
Constructor, opens the file and reads the header infomation.

Parameters:
file - The file to be opened, includes path and .dbf
Throws:
java.io.IOException - If the file can't be opened.
DbfFileException - If there is an error reading header.
Method Detail

getLastUpdate

public java.lang.String getLastUpdate()
Returns the date of the last update of the file as a string.


getLastRec

public int getLastRec()
Returns the number of records in the database file.


getRecSize

public int getRecSize()
Returns the size of the records in the database file.


getNumFields

public int getNumFields()
Returns the number of fields in the records in the database file.


getFieldName

public java.lang.String getFieldName(int row)

getFieldType

public java.lang.String getFieldType(int row)

getFileSize

public int getFileSize()
Returns the size of the database file.


GetNextDbfRec

public java.lang.StringBuffer GetNextDbfRec()
                                     throws java.io.IOException
gets the next record and returns it as a string. This method works on a sequential stream and can not go backwards. Only useful if you want to read the whole file in one.

Throws:
java.io.IOException - on read error.

GetDbfRec

public java.lang.StringBuffer GetDbfRec(int row)
                                 throws java.io.IOException
fetches the rowth row of the file

Parameters:
row - - the row to fetch
Throws:
java.io.IOException - on read error.

ParseDbfRecord

public java.util.Vector ParseDbfRecord(int row)
                                throws java.io.IOException
fetches the rowth row of the file and parses it into an vector of objects.

Parameters:
row - - the row to fetch
Throws:
java.io.IOException - on read error.

ParseRecordColumn

public java.lang.Object ParseRecordColumn(java.lang.StringBuffer rec,
                                          int wantedCol)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

ParseRecord

public java.util.Vector ParseRecord(java.lang.StringBuffer rec)
Parses the record stored in the StringBuffer rec into a vector of objects

Parameters:
StringBuffer - rec - the record to be parsed.

getIntegerCol

public java.lang.Integer[] getIntegerCol(int col)
                                  throws java.io.IOException,
                                         DbfFileException
Fetches a column of Integers from the database file.

Parameters:
int - col - the column to fetch
Throws:
java.io.IOException - - on read error
DbfFileException - - column is not an Integer.

getIntegerCol

public java.lang.Integer[] getIntegerCol(int col,
                                         int start,
                                         int end)
                                  throws java.io.IOException,
                                         DbfFileException
Fetches a part column of Integers from the database file.

Parameters:
int - col - the column to fetch
int - start - the row to start fetching from
int - end - the row to stop fetching at.
Throws:
java.io.IOException - - on read error
DbfFileException - - column is not an Integer.

getFloatCol

public java.lang.Double[] getFloatCol(int col)
                               throws DbfFileException,
                                      java.io.IOException
Fetches a column of Double from the database file.

Parameters:
int - col - the column to fetch
Throws:
java.io.IOException - - on read error
DbfFileException - - column is not an Integer.

getFloatCol

public java.lang.Double[] getFloatCol(int col,
                                      int start,
                                      int end)
                               throws DbfFileException,
                                      java.io.IOException
Fetches a part column of Double from the database file.

Parameters:
int - col - the column to fetch
int - start - the row to start fetching from
int - end - the row to stop fetching at.
Throws:
java.io.IOException - - on read error
DbfFileException - - column is not an Integer.

getStringCol

public java.lang.String[] getStringCol(int col)
                                throws DbfFileException,
                                       java.io.IOException
Fetches a column of Strings from the database file.

Parameters:
int - col - the column to fetch
Throws:
java.io.IOException - - on read error
DbfFileException - - column is not an Integer.

getStringCol

public java.lang.String[] getStringCol(int col,
                                       int start,
                                       int end)
                                throws DbfFileException,
                                       java.io.IOException
Fetches a part column of Strings from the database file.

Parameters:
int - col - the column to fetch
int - start - the row to start fetching from
int - end - the row to stop fetching at.
Throws:
java.io.IOException - - on read error
DbfFileException - - column is not an Integer.

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception