Class 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)
    • Field Detail

      • MILLIS_SINCE_4713

        public static long MILLIS_SINCE_4713
        Returns the number of millis at January 1st 4713 BC

        Calendar refCal = (Calendar) new GregorianCalendar(TimeZone.getTimeZone("UTC")); refCal.set(Calendar.ERA, GregorianCalendar.BC); refCal.set(Calendar.YEAR, 4713); refCal.set(Calendar.MONTH, Calendar.JANUARY); refCal.set(Calendar.DAY_OF_MONTH, 1); refCal.set(Calendar.HOUR, 12); refCal.set(Calendar.MINUTE, 0); refCal.set(Calendar.SECOND, 0); refCal.set(Calendar.MILLISECOND, 0); MILLIS_SINCE_4713 = refCal.getTimeInMillis() - 43200000L; //(43200000L: 12 hour correction factor taken from DBFViewer2000)

    • Constructor Detail

      • DbaseFileHeader

        public DbaseFileHeader()
      • DbaseFileHeader

        public DbaseFileHeader​(Charset charset)
    • Method Detail

      • getFieldClass

        public 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 Long or Double (depends on field's decimal count and fieldLength)
         F (Floating)  -> Double
         L (Logical)   -> Boolean
         D (Date)      -> java.util.Date (Without time)
        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​(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
        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​(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.
      • 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​(ReadableByteChannel channel)
                        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.
      • readHeader

        public void readHeader​(ByteBuffer in)
                        throws IOException
        Read the header data from the DBF file.
        Parameters:
        in - The ByteBuffer to read the header from
        Throws:
        IOException - If errors occur while reading.
      • getLargestFieldSize

        public int getLargestFieldSize()
        Get the largest field size of this table.
        Returns:
        The largest field size in 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​(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.
      • getLengthForRecords

        public long getLengthForRecords​(int records)
        Returns the expected file size for the given number of records in the file