Class DbaseFileHeader
java.lang.Object
org.h2gis.functions.io.dbf.internal.DbaseFileHeader
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
FieldsModifier and TypeFieldDescriptionstatic StringEncoding of String, found in Language Code Page DBF Header, use ISO-8859-1 as default valuestatic byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a column to this DbaseFileHeader.intgetFieldDecimalCount(int inIndex) Get the decimal count of this field.intgetFieldLength(int inIndex) Returns the field length in bytes.getFieldName(int inIndex) Get the field name.chargetFieldType(int inIndex) Get the character class of the field.intGet the length of the headerintGet the largest field size of this table.Get the date this file was last updated.intReturn the number of fields in the records.intReturn the number of records in the fileintGet the length of the records in bytes.voidreadHeader(FileChannel channel, String forceEncoding) Read the header data from the DBF file.intremoveColumn(String inFieldName) Remove a column from this DbaseFileHeader.booleansetEncoding(String encoding) Set file encodingvoidsetNumRecords(int inNumRecords) Set the number of records in the filetoString()Get a simple representation of this header.voidWrite the header data to the DBF file.
-
Field Details
-
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 Details
-
DbaseFileHeader
public DbaseFileHeader()
-
-
Method Details
-
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–DOSField 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
Remove a column from this DbaseFileHeader. todo This is really ugly, don't know who wrote it, but it needs fixin...- 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
- 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
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
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
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
Set file encoding- Parameters:
encoding- Encoding to set- Returns:
- True if the encoding can be set to DBF file
-
writeHeader
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
Get a simple representation of this header.
-