org.geotools.data.shapefile.dbf
Class DbaseFileHeader

java.lang.Object
  extended byorg.geotools.data.shapefile.dbf.DbaseFileHeader

public class DbaseFileHeader
extends java.lang.Object

Class to represent the header of a Dbase III file. Creation date: (5/15/2001 5:15:30 PM)


Constructor Summary
DbaseFileHeader()
           
 
Method Summary
 void addColumn(java.lang.String inFieldName, char inFieldType, int inFieldLength, int inDecimalCount)
          Add a column to this DbaseFileHeader.
 java.lang.Class getFieldClass(int i)
          Determine the most appropriate Java Class for representing the data in the field.
 int getFieldDecimalCount(int inIndex)
          Get the decimal count of this field.
 int getFieldLength(int inIndex)
          Returns the field length in bytes.
 java.lang.String getFieldName(int inIndex)
          Get the field name.
 char getFieldType(int inIndex)
          Get the character class of the field.
 int getHeaderLength()
          Get the length of the header
 int getLargestFieldSize()
          Get the largest field size of this table.
 java.util.Date getLastUpdateDate()
          Get the date this file was last updated.
 int getNumFields()
          Return the number of fields in the records.
 int getNumRecords()
          Return the number of records in the file
 int getRecordLength()
          Get the length of the records in bytes.
 void readHeader(java.nio.channels.ReadableByteChannel channel)
          Read the header data from the DBF file.
 int removeColumn(java.lang.String inFieldName)
          Remove a column from this DbaseFileHeader.
 void setNumRecords(int inNumRecords)
          Set the number of records in the file
 java.lang.String toString()
          Get a simple representation of this header.
 void writeHeader(java.nio.channels.WritableByteChannel out)
          Write the header data to the DBF file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DbaseFileHeader

public DbaseFileHeader()
Method Detail

getFieldClass

public java.lang.Class getFieldClass(int i)
Determine the most appropriate Java Class for representing the data in the field.
 All packages are java.lang unless otherwise specified.
 C (Character) -> String
 N (Numeric)   -> Integer or Double (depends on field's decimal count)
 F (Floating)  -> Double
 L (Logical)   -> Boolean
 D (Date)      -> java.util.Date
 Unknown       -> String
 

Parameters:
i - The index of the field, from 0 to getNumFields() - 1 .
Returns:
A Class which closely represents the dbase field type.

addColumn

public void addColumn(java.lang.String inFieldName,
                      char inFieldType,
                      int inFieldLength,
                      int inDecimalCount)
               throws DbaseFileException
Add a column to this DbaseFileHeader. The type is one of (C N L or D) character, number, logical(true/false), or date. The Field length is the total length in bytes reserved for this column. The decimal count only applies to numbers(N), and floating point values (F), and refers to the number of characters to reserve after the decimal point. Don't expect miracles from this...
 Field Type MaxLength
 ---------- ---------
 C          254
 D          8
 F          20
 N          18
 

Parameters:
inFieldName - The name of the new field, must be less than 10 characters or it gets truncated.
inFieldType - A character representing the dBase field, ( see above ). Case insensitive.
inFieldLength - The length of the field, in bytes ( see above )
inDecimalCount - For numeric fields, the number of decimal places to track.
Throws:
DbaseFileException - If the type is not recognized.

removeColumn

public int removeColumn(java.lang.String inFieldName)
Remove a column from this DbaseFileHeader.

Parameters:
inFieldName - The name of the field, will ignore case and trim.
Returns:
index of the removed column, -1 if no found
To Do:
This is really ugly, don't know who wrote it, but it needs fixin...

getFieldLength

public int getFieldLength(int inIndex)
Returns the field length in bytes.

Parameters:
inIndex - The field index.
Returns:
The length in bytes.

getFieldDecimalCount

public int getFieldDecimalCount(int inIndex)
Get the decimal count of this field.

Parameters:
inIndex - The field index.
Returns:
The decimal count.

getFieldName

public java.lang.String getFieldName(int inIndex)
Get the field name.

Parameters:
inIndex - The field index.
Returns:
The name of the field.

getFieldType

public char getFieldType(int inIndex)
Get the character class of the field.

Parameters:
inIndex - The field index.
Returns:
The dbase character representing this field.

getLastUpdateDate

public java.util.Date getLastUpdateDate()
Get the date this file was last updated.

Returns:
The Date last modified.

getNumFields

public int getNumFields()
Return the number of fields in the records.

Returns:
The number of fields in this table.

getNumRecords

public int getNumRecords()
Return the number of records in the file

Returns:
The number of records in this table.

getRecordLength

public int getRecordLength()
Get the length of the records in bytes.

Returns:
The number of bytes per record.

getHeaderLength

public int getHeaderLength()
Get the length of the header

Returns:
The length of the header in bytes.

readHeader

public void readHeader(java.nio.channels.ReadableByteChannel channel)
                throws java.io.IOException
Read the header data from the DBF file.

Parameters:
channel - A readable byte channel. If you have an InputStream you need to use, you can call java.nio.Channels.getChannel(InputStream in).
Throws:
java.io.IOException - If errors occur while reading.

getLargestFieldSize

public int getLargestFieldSize()
Get the largest field size of this table.

Returns:
The largt field size iiin bytes.

setNumRecords

public void setNumRecords(int inNumRecords)
Set the number of records in the file

Parameters:
inNumRecords - The number of records.

writeHeader

public void writeHeader(java.nio.channels.WritableByteChannel out)
                 throws java.io.IOException
Write the header data to the DBF file.

Parameters:
out - A channel to write to. If you have an OutputStream you can obtain the correct channel by using java.nio.Channels.newChannel(OutputStream out).
Throws:
java.io.IOException - If errors occur.

toString

public java.lang.String toString()
Get a simple representation of this header.

Returns:
A String representing the state of the header.


Copyright © GeoTools. All Rights Reserved.