Class DBFUtils

java.lang.Object
io.github.zazalng.utility.DBFUtils

public final class DBFUtils extends Object
Utility class containing static methods for decoding specific DBF field data types.

These methods handle conversions from raw byte arrays or padded strings into appropriate Java types such as LocalDate, BigDecimal, and LocalDateTime.

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

    • parseDate

      public static LocalDate parseDate(String text)
      Parses a DBF Date string (format YYYYMMDD) into a LocalDate.
      Parameters:
      text - The 8-character string representing the date.
      Returns:
      The parsed LocalDate, or null if the string is invalid or empty.
    • parseNumeric

      public static BigDecimal parseNumeric(String text)
      Parses a DBF Numeric or Float string into a BigDecimal.
      Parameters:
      text - The string containing the numeric value, possibly padded with spaces.
      Returns:
      The parsed BigDecimal, or null if the string cannot be parsed.
    • parseDoubleBinary

      public static BigDecimal parseDoubleBinary(byte[] data)
      Decodes 8 raw bytes representing a VFP Double/Currency type (IEEE 754 64-bit float) into a BigDecimal.
      Parameters:
      data - The 8-byte array containing the little-endian binary double.
      Returns:
      The decoded value as a BigDecimal, or null if data is insufficient.
    • parseIntBinary

      public static Integer parseIntBinary(byte[] data)
      Decodes 4 raw bytes representing a VFP Integer type into an Integer.
      Parameters:
      data - The 4-byte array containing the little-endian binary integer.
      Returns:
      The decoded Integer, or null if data is insufficient.
    • parseDateTime

      public static LocalDateTime parseDateTime(byte[] data)
      Decodes 8 raw bytes representing a VFP or dBase Level 7 DateTime/Timestamp into a LocalDateTime.

      The first 4 bytes are the Julian day number (since 1/1/4713 BC). The second 4 bytes are milliseconds since midnight.

      Parameters:
      data - The 8-byte array containing the little-endian Julian day and milliseconds.
      Returns:
      The decoded LocalDateTime, or null if data is insufficient or decoding fails.