Package io.github.zazalng.entity
Class DBFField
java.lang.Object
io.github.zazalng.entity.DBFField
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 Summary
Modifier and TypeMethodDescriptionDecodes the raw byte data for this field into an appropriate Java object based on the field's type.intGets the number of decimal places for Numeric and Float fields.intGets the total length of the field data in bytes.getName()Gets the name of the field (up to 10 characters).getType()Gets the data type of the field.static DBFFieldread(ByteBuffer buf, Charset charset) Reads a single 32-byte field descriptor from theByteBuffer.
-
Method Details
-
read
Reads a single 32-byte field descriptor from theByteBuffer. The buffer's position is advanced by 32 bytes to point to the next descriptor or the end-of-fields marker.- Parameters:
buf- TheByteBuffercontaining the field descriptor data.charset- The character set used to decode the field name (e.g.,DBFEncoding.toCharset()).- Returns:
- A new
DBFFieldinstance containing the parsed metadata.
-
decode
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). Returnsnullif the raw data is empty, invalid, or cannot be parsed. Returns the raw byte array for unhandled types (MEMO, GENERAL, etc.).
-
getName
Gets the name of the field (up to 10 characters).- Returns:
- The field name.
-
getType
Gets the data type of the field.- Returns:
- The
DBFDataTypeenum 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.
-