Class DatevFile

java.lang.Object
io.github.mrtyldr.datev.plain.DatevFile
All Implemented Interfaces:
Iterable<List<String>>

public final class DatevFile extends Object implements Iterable<List<String>>
Builds and writes rows for one of the fixed DATEV Buchungsstapel schemas without dependencies.

The implementation uses a strict single-record CSV parser and a StringBuilder-based serializer. It does not perform DATEV field-semantic validation unless a BiConsumer validator is explicitly supplied. The validator receives the DATEV format version and an immutable, aligned row without linking either side to an implementation-specific validator type. Instances are mutable and not thread-safe. Use DatevStreamWriter when booking rows should be written once without being retained.

Attach a DatevMetadata through builder() to emit the mandatory EXTF management record and produce a complete, importable Buchungsstapel file.

  • Field Details

    • DEFAULT_DELIMITER

      public static final char DEFAULT_DELIMITER
      Separator required by DATEV CSV files.
      See Also:
    • DEFAULT_LINE_SEPARATOR

      public static final String DEFAULT_LINE_SEPARATOR
      Record separator required by DATEV CSV files.
      See Also:
    • DEFAULT_CHARSET

      public static final Charset DEFAULT_CHARSET
      Default encoding used by DATEV accounting imports.
    • MAX_DATA_ROWS

      public static final int MAX_DATA_ROWS
      Maximum number of booking records in a DATEV Buchungsstapel file.
      See Also:
  • Method Details

    • builder

      public static DatevFile.Builder builder()
      Creates a builder for the current v13 schema.
      Returns:
      a new builder
    • builder

      public static DatevFile.Builder builder(io.github.mrtyldr.datev.core.DatevSchema schema)
      Creates a builder for an explicit fixed schema.
      Parameters:
      schema - the fixed schema to use
      Returns:
      a new builder
    • withDefaults

      public static DatevFile withDefaults()
      Creates an unvalidated file using the current v13 schema.
      Returns:
      a new v13 file
    • withDefaults

      public static DatevFile withDefaults(BiConsumer<Integer,List<String>> validator)
      Creates a current v13 file using an explicitly supplied validator.
      Parameters:
      validator - validator invoked for each append
      Returns:
      a new validated v13 file
    • legacyV12

      public static DatevFile legacyV12()
      Creates an unvalidated file using the legacy v12 schema.
      Returns:
      a new v12 file
    • legacyV12

      public static DatevFile legacyV12(BiConsumer<Integer,List<String>> validator)
      Creates a legacy v12 file using an explicitly supplied validator.
      Parameters:
      validator - validator invoked for each append
      Returns:
      a new validated v12 file
    • forSchema

      public static DatevFile forSchema(io.github.mrtyldr.datev.core.DatevSchema schema)
      Creates an unvalidated file using one of the fixed schemas.
      Parameters:
      schema - fixed schema to use
      Returns:
      a new file
    • forSchema

      public static DatevFile forSchema(io.github.mrtyldr.datev.core.DatevSchema schema, BiConsumer<Integer,List<String>> validator)
      Creates a file using one fixed schema and an explicitly supplied validator.
      Parameters:
      schema - fixed schema to use
      validator - validator invoked for each append
      Returns:
      a new validated file
    • schema

      public io.github.mrtyldr.datev.core.DatevSchema schema()
      Returns the fixed schema selected for this file.
      Returns:
      the selected schema
    • headers

      public List<String> headers()
      Returns the immutable official headings in output order.
      Returns:
      fixed ordered headings
    • charset

      public Charset charset()
      Returns the output encoding.
      Returns:
      Windows-1252
    • validator

      public Optional<BiConsumer<Integer,List<String>>> validator()
      Returns the explicitly configured validator, if any.
      Returns:
      the configured validator
    • metadata

      public Optional<io.github.mrtyldr.datev.core.DatevMetadata> metadata()
      Returns the configured EXTF management record, if any.
      Returns:
      the configured metadata
    • isCompleteExtf

      public boolean isCompleteExtf()
      Returns whether output contains the mandatory EXTF management record.

      Without metadata this file emits only the heading and booking records, which is not a complete DATEV-Format file.

      Returns:
      true if metadata is configured
    • rowCount

      public int rowCount()
      Returns the number of appended data rows.
      Returns:
      row count
    • isEmpty

      public boolean isEmpty()
      Returns whether no data rows have been appended.
      Returns:
      true when empty
    • rows

      public List<List<String>> rows()
      Returns an immutable snapshot of immutable header-aligned rows.
      Returns:
      immutable row snapshot
    • iterator

      public Iterator<List<String>> iterator()
      Returns an iterator over an immutable snapshot of the current rows.
      Specified by:
      iterator in interface Iterable<List<String>>
    • append

      public void append(String semicolonSeparatedRow)
      Parses and appends exactly one strict semicolon-delimited CSV record.

      Quoted values, doubled quote escaping and trailing empty cells are supported. Newlines, malformed quotes and a number of cells different from the fixed schema are rejected.

      Parameters:
      semicolonSeparatedRow - exactly one complete CSV row
    • append

      public void append(String[] orderedValues)
      Appends a complete positional row from a defensively copied array.
      Parameters:
      orderedValues - values in fixed heading order
    • append

      public void append(Collection<String> orderedValues)
      Appends a complete positional row from a defensively copied collection.
      Parameters:
      orderedValues - values in fixed heading order
    • appendValues

      public void appendValues(Object... orderedValues)
      Appends a complete positional row, converting non-null values with String.valueOf(Object).
      Parameters:
      orderedValues - values in fixed heading order
    • append

      public void append(Map<String,?> valuesByHeader)
      Appends a sparse row addressed by exact official heading names.

      Missing headings become empty cells. Unknown and null headings are rejected.

      Parameters:
      valuesByHeader - values addressed by exact official headings
    • append

      public void append(io.github.mrtyldr.datev.core.DatevColumn<?>... columns)
      Appends a sparse formatted row addressed by exact official heading names.
      Parameters:
      columns - columns to align by heading
    • append

      public void append(Iterable<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns)
      Appends formatted columns from an iterable.

      The different raw parameter type avoids erasure conflict with append(Collection).

      Parameters:
      columns - columns to align by heading
    • appendColumns

      public void appendColumns(Collection<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns)
      Appends a sparse formatted row from a collection.

      All headings are resolved before any formatter runs. Formatting and validation finish before the row is committed.

      Parameters:
      columns - columns to align by heading
    • writeTo

      public void writeTo(OutputStream output)
      Writes the header and all current rows without closing the caller-owned stream.
      Parameters:
      output - destination stream
    • write

      public void write(OutputStream output)
      Parameters:
      output - destination stream
    • writeTo

      public void writeTo(Writer output)
      Writes the header and all current rows one record at a time without closing the caller-owned writer. Appended rows remain retained by this file.
      Parameters:
      output - destination writer
    • write

      public void write(Writer output)
      Alias for writeTo(Writer).
      Parameters:
      output - destination writer
    • toByteArray

      public byte[] toByteArray()
      Returns the complete fixed-header CSV encoded as Windows-1252 bytes.
      Returns:
      encoded CSV
    • toCsvString

      public String toCsvString()
      Returns the complete fixed-header CSV as characters.
      Returns:
      CSV text