Class DBFHeader

java.lang.Object
io.github.zazalng.entity.DBFHeader

public final class DBFHeader extends Object
Represents the structure and metadata of a DBF file.

This class is responsible for reading and parsing the initial 32-byte header block and the subsequent field descriptor array from the DBF file stream. It also calculates the starting position of the data records.

Since:
1.0.0
Author:
Zazalng
See Also:
  • Constructor Details

    • DBFHeader

      public DBFHeader(SeekableByteChannel ch, DBFEncoding encoding) throws IOException
      Reads and parses the DBF header structure and field descriptors from the given channel. The channel's position is moved to the start of the data records upon successful construction.
      Parameters:
      ch - The SeekableByteChannel positioned at the start of the DBF file.
      encoding - The DBFEncoding to use for text fields. If null, the encoding determined by the LDID byte is used.
      Throws:
      IOException - If an I/O error occurs while reading the channel.
  • Method Details

    • version

      public DBFVersion version()
      Gets the version/dialect of the DBF file format.
      Returns:
      The DBFVersion of the file.
    • recordCount

      public int recordCount()
      Gets the total number of data records specified in the header.
      Returns:
      The record count.
    • headerLength

      public short headerLength()
      Gets the total length of the header structure (including field descriptors and the terminal 0x0D), in bytes.
      Returns:
      The header length.
    • recordLength

      public short recordLength()
      Gets the length of a single data record, including the one-byte deletion flag, in bytes.
      Returns:
      The record length.
    • encoding

      public DBFEncoding encoding()
      Gets the character encoding defined by the Language Driver ID (LDID) byte in the header.
      Returns:
      The DBFEncoding of the file.
    • fields

      public List<DBFField> fields()
      Gets an unmodifiable list of the DBFField descriptors parsed from the header.
      Returns:
      An unmodifiable List of DBFField objects.
    • readRecords

      public List<DBFRow> readRecords(SeekableByteChannel ch) throws IOException
      Reads all data records from the current position of the channel until the record count is reached.
      Parameters:
      ch - The SeekableByteChannel, assumed to be positioned at the start of the data records.
      Returns:
      A list of DBFRow objects representing the data records.
      Throws:
      IOException - If an I/O error occurs during reading.