Package io.github.zazalng.entity
Class DBFHeader
java.lang.Object
io.github.zazalng.entity.DBFHeader
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 Summary
ConstructorsConstructorDescriptionDBFHeader(SeekableByteChannel ch, DBFEncoding encoding) Reads and parses the DBF header structure and field descriptors from the given channel. -
Method Summary
Modifier and TypeMethodDescriptionencoding()Gets the character encoding defined by the Language Driver ID (LDID) byte in the header.fields()Gets an unmodifiable list of theDBFFielddescriptors parsed from the header.shortGets the total length of the header structure (including field descriptors and the terminal 0x0D), in bytes.Reads all data records from the current position of the channel until the record count is reached.intGets the total number of data records specified in the header.shortGets the length of a single data record, including the one-byte deletion flag, in bytes.version()Gets the version/dialect of the DBF file format.
-
Constructor Details
-
DBFHeader
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- TheSeekableByteChannelpositioned at the start of the DBF file.encoding- TheDBFEncodingto use for text fields. Ifnull, the encoding determined by the LDID byte is used.- Throws:
IOException- If an I/O error occurs while reading the channel.
-
-
Method Details
-
version
Gets the version/dialect of the DBF file format.- Returns:
- The
DBFVersionof 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
Gets the character encoding defined by the Language Driver ID (LDID) byte in the header.- Returns:
- The
DBFEncodingof the file.
-
fields
Gets an unmodifiable list of theDBFFielddescriptors parsed from the header.- Returns:
- An unmodifiable
ListofDBFFieldobjects.
-
readRecords
Reads all data records from the current position of the channel until the record count is reached.- Parameters:
ch- TheSeekableByteChannel, assumed to be positioned at the start of the data records.- Returns:
- A list of
DBFRowobjects representing the data records. - Throws:
IOException- If an I/O error occurs during reading.
-