Class DBFField

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

public final class DBFField extends Object
Represents a single field (column) descriptor from the DBF file header.

This final class holds the metadata required to interpret data stored in the records, including the field's name, data type, length, and decimal precision. This structure is compatible with older Java Development Kits (e.g., JDK 8).

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

    • read

      public static DBFField read(ByteBuffer buf, Charset charset)
      Reads a single 32-byte field descriptor from the ByteBuffer. The buffer's position is advanced by 32 bytes to point to the next descriptor or the end-of-fields marker.
      Parameters:
      buf - The ByteBuffer containing the field descriptor data.
      charset - The character set used to decode the field name (e.g., DBFEncoding.toCharset()).
      Returns:
      A new DBFField instance containing the parsed metadata.
    • decode

      public Object decode(byte[] data, Charset charset)
      Decodes the raw byte data for this field into an appropriate Java object based on the field's type.
      Parameters:
      data - The raw byte array containing the field data for a single record.
      charset - The character set used for decoding text-based types (e.g., CHARACTER, NUMERIC, DATE).
      Returns:
      The decoded value as an Object (e.g., String, Date, Double, Integer, Boolean). Returns null if the raw data is empty, invalid, or cannot be parsed. Returns the raw byte array for unhandled types (MEMO, GENERAL, etc.).
    • getName

      public String getName()
      Gets the name of the field (up to 10 characters).
      Returns:
      The field name.
    • getType

      public DBFDataType getType()
      Gets the data type of the field.
      Returns:
      The DBFDataType enum constant.
    • getLength

      public int getLength()
      Gets the total length of the field data in bytes.
      Returns:
      The field length.
    • getDecimalCount

      public int getDecimalCount()
      Gets the number of decimal places for Numeric and Float fields.
      Returns:
      The decimal count.