Class DbaseFileHeader

java.lang.Object
org.h2gis.functions.io.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 Details

    • 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 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–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. 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

      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.