Class DbfWriter

java.lang.Object
ch.so.agi.gretl.internal.shapefile.core.DbfWriter
All Implemented Interfaces:
AutoCloseable

public final class DbfWriter extends Object implements AutoCloseable
Low-level writer for the .dbf attribute table (dBASE III).

The header is written first with a record count of 0 and patched at the end via patchRecordCount(int). Records are written one at a time; nothing is buffered.

Header geometry matches DbfReader: headerLength = 32 + 32 * numFields + 1 (including the 0x0D field terminator) and recordLength = 1 + sum(fieldLengths) (including the leading deleted flag).

The FileChannel is owned by ShapefileDatasetWriter; close() therefore does not close the channel.

  • Constructor Details

  • Method Details

    • headerLength

      public int headerLength()
    • recordLength

      public int recordLength()
    • writeHeader

      public void writeHeader(int recordCount) throws IOException
      Writes the full DBF header at the start of the file with the given record count.
      Throws:
      IOException
    • writeRecord

      public void writeRecord(Object[] values) throws IOException, ShapefileMappingException
      Appends a single record at the current channel position.
      Throws:
      IOException
      ShapefileMappingException
    • writeEndOfFile

      public void writeEndOfFile() throws IOException
      Writes the trailing 0x1A end-of-file marker at the current channel position.
      Throws:
      IOException
    • patchRecordCount

      public void patchRecordCount(int recordCount) throws IOException
      Patches the 4-byte little-endian record count at offset 4 in the header.
      Throws:
      IOException
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable