org.h2gis.drivers.dbf.internal
Class DbaseFileHeader

java.lang.Object
  extended by org.h2gis.drivers.dbf.internal.DbaseFileHeader

public class DbaseFileHeader
extends Object

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

See Also:
"http://svn.geotools.org/geotools/tags/2.3.1/plugin/shapefile/src/org/geotools/data/shapefile/dbf/DbaseFileHeader.java"

Field Summary
static String DEFAULT_ENCODING
          Encoding of String, found in Language Code Page DBF Header, use ISO-8859-1 as default value
static byte DEFAULT_ENCODING_FLAG
           
 
Constructor Summary
DbaseFileHeader()
           
 
Method Summary
 void addColumn(String inFieldName, char inFieldType, int inFieldLength, int inDecimalCount)
          Add a column to this DbaseFileHeader.
 int getFieldDecimalCount(int inIndex)
          Get the decimal count of this field.
 int getFieldLength(int inIndex)
          Returns the field length in bytes.
 String getFieldName(int inIndex)
          Get the field name.
 char getFieldType(int inIndex)
          Get the character class of the field.
 String getFileEncoding()
           
 int getHeaderLength()
          Get the length of the header
 int getLargestFieldSize()
          Get the largest field size of this table.
 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(FileChannel channel, String forceEncoding)
          Read the header data from the DBF file.
 int removeColumn(String inFieldName)
          Remove a column from this DbaseFileHeader.
 boolean setEncoding(String encoding)
          Set file encoding
 void setNumRecords(int inNumRecords)
          Set the number of records in the file
 String toString()
          Get a simple representation of this header.
 void writeHeader(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
 

Field Detail

DEFAULT_ENCODING

public static String DEFAULT_ENCODING
Encoding of String, found in Language Code Page DBF Header, use ISO-8859-1 as default value


DEFAULT_ENCODING_FLAG

public static byte DEFAULT_ENCODING_FLAG
Constructor Detail

DbaseFileHeader

public DbaseFileHeader()
Method Detail

addColumn

public void addColumn(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... "02" => "cp850", # International MS–DOS

 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 - "02" => "cp850", # International MS–DOS If the type is not recognized.

removeColumn

public int removeColumn(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

getFieldLength

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

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

getFileEncoding

public String getFileEncoding()
Returns:
File Encoding, ISO-8859-1 if the file encoding is not recognized

getFieldDecimalCount

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

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

getFieldName

public 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 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(FileChannel channel,
                       String forceEncoding)
                throws 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:
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.

setEncoding

public boolean setEncoding(String encoding)
Set file encoding

Parameters:
encoding - Encoding to set
Returns:
True if the encoding can be set to DBF file

writeHeader

public void writeHeader(WritableByteChannel out)
                 throws 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:
IOException - If errors occur.

toString

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

Overrides:
toString in class Object
Returns:
A String representing the state of the header.


Copyright © 2015 IRSTV CNRS-FR-2488. All Rights Reserved.