Class DatevFile

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

public final class DatevFile extends Object implements Iterable<List<String>>
Builds header-aligned DATEV CSV rows and writes a complete Buchungsstapel file.

A file's header is immutable. Appended rows are validated and converted atomically into that header's order. The class itself is an iterable of rows, so any row consumer can read it directly.

Serialization goes through DatevCsv, so this module has no third-party dependencies. For Univocity interoperability add datev-exporter-advanced-univocity.

Instances are mutable and are not thread-safe.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builds a file with immutable header configuration.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Charset
    The default character set accepted by DATEV accounting imports.
    static final char
    The separator required by the DATEV CSV format.
    static final String
    The record separator required by the DATEV CSV format.
    static final int
    Maximum number of booking records in one DATEV Buchungsstapel file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(io.github.mrtyldr.datev.core.DatevColumn<?>... columns)
    Appends a sparse formatted row.
    void
    append(Iterable<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns)
    Appends a sparse formatted row from an iterable of columns.
    void
    append(String semicolonSeparatedRow)
    Appends a semicolon-delimited CSV row.
    void
    append(String[] orderedValues)
    Appends a complete positional row from an array.
    void
    append(Collection<String> orderedValues)
    Appends a complete positional row from a collection.
    void
    append(Map<String,?> valuesByHeader)
    Appends a sparse row addressed by canonical header keys or configured output names.
    void
    appendColumns(Collection<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns)
    Appends a sparse formatted row from a collection of columns.
    void
    appendValues(Object... orderedValues)
    Appends a complete positional row containing arbitrary values converted with String.valueOf(Object).
    Starts a builder with the current default DATEV Buchungsstapel header.
    builder(io.github.mrtyldr.datev.core.DatevHeader header)
    Starts a builder with a custom or preconfigured header.
    Returns the charset used by writeTo(OutputStream).
    io.github.mrtyldr.datev.core.DatevHeader
    Returns this file's immutable header definition.
    Returns the output header names in their configured order.
    boolean
    Returns whether convenience output contains a complete EXTF management record.
    boolean
    Returns whether no data rows have been appended.
    Returns an iterator over an immutable snapshot of the current rows.
    Optional<io.github.mrtyldr.datev.core.DatevMetadata>
    Returns the optional EXTF management-record metadata.
    int
    Returns the number of appended rows.
    Returns an immutable snapshot of all rows.
    byte[]
    Returns the complete CSV as bytes in charset().
    Returns the complete CSV as characters, primarily for inspection and testing.
    io.github.mrtyldr.datev.core.DatevValidationMode
    Returns the configured semantic validation mode.
    static DatevFile
    Creates a file with the current default DATEV Buchungsstapel header and writer settings.
    static DatevFile
    withDefaults(io.github.mrtyldr.datev.core.DatevMetadata metadata)
    Creates a complete Buchungsstapel v13 file with a typed EXTF management record.
    static DatevFile
    withHeader(io.github.mrtyldr.datev.core.DatevHeader header)
    Creates a file with an already configured immutable header.
    static DatevFile
    withHeader(String semicolonSeparatedHeader)
    Creates a file with a semicolon-separated custom header.
    static DatevFile
    withHeader(String[] header)
    Creates a file with a custom header.
    static DatevFile
    Creates a file with a custom header.
    void
    void
    Writes the header and all current rows to an output stream without closing it.
    void
    writeTo(Writer output)
    Writes the header and all current rows to a character writer without closing it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • DEFAULT_DELIMITER

      public static final char DEFAULT_DELIMITER
      The separator required by the DATEV CSV format.
      See Also:
    • DEFAULT_LINE_SEPARATOR

      public static final String DEFAULT_LINE_SEPARATOR
      The record separator required by the DATEV CSV format.
      See Also:
    • DEFAULT_CHARSET

      public static final Charset DEFAULT_CHARSET
      The default character set accepted by DATEV accounting imports.
    • MAX_DATA_ROWS

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

    • withDefaults

      public static DatevFile withDefaults()
      Creates a file with the current default DATEV Buchungsstapel header and writer settings.
      Returns:
      a new file using the default header and settings
    • withDefaults

      public static DatevFile withDefaults(io.github.mrtyldr.datev.core.DatevMetadata metadata)
      Creates a complete Buchungsstapel v13 file with a typed EXTF management record.
      Parameters:
      metadata - the management-record metadata
      Returns:
      a new strictly validated v13 file
    • withHeader

      public static DatevFile withHeader(String semicolonSeparatedHeader)
      Creates a file with a semicolon-separated custom header.
      Parameters:
      semicolonSeparatedHeader - the complete header row separated by semicolons
      Returns:
      a new file using the supplied header
    • withHeader

      public static DatevFile withHeader(String[] header)
      Creates a file with a custom header. The input array is defensively copied.
      Parameters:
      header - the output header names in column order
      Returns:
      a new file using the supplied header
    • withHeader

      public static DatevFile withHeader(List<String> header)
      Creates a file with a custom header. The input list is defensively copied.
      Parameters:
      header - the output header names in column order
      Returns:
      a new file using the supplied header
    • withHeader

      public static DatevFile withHeader(io.github.mrtyldr.datev.core.DatevHeader header)
      Creates a file with an already configured immutable header.
      Parameters:
      header - the immutable header configuration to use
      Returns:
      a new file using the supplied header
    • builder

      public static DatevFile.Builder builder()
      Starts a builder with the current default DATEV Buchungsstapel header.
      Returns:
      a new builder using the default header
    • builder

      public static DatevFile.Builder builder(io.github.mrtyldr.datev.core.DatevHeader header)
      Starts a builder with a custom or preconfigured header.
      Parameters:
      header - the initial immutable header configuration
      Returns:
      a new builder using the supplied header
    • header

      public io.github.mrtyldr.datev.core.DatevHeader header()
      Returns this file's immutable header definition.
      Returns:
      this file's header definition
    • headers

      public List<String> headers()
      Returns the output header names in their configured order.
      Returns:
      the ordered, immutable output header names
    • charset

      public Charset charset()
      Returns the charset used by writeTo(OutputStream).
      Returns:
      the output charset
    • metadata

      public Optional<io.github.mrtyldr.datev.core.DatevMetadata> metadata()
      Returns the optional EXTF management-record metadata.
      Returns:
      metadata for a complete EXTF file, or an empty optional for a data-only file
    • validationMode

      public io.github.mrtyldr.datev.core.DatevValidationMode validationMode()
      Returns the configured semantic validation mode.
      Returns:
      the validation mode applied before a row is committed
    • isCompleteExtf

      public boolean isCompleteExtf()
      Returns whether convenience output contains a complete EXTF management record.
      Returns:
      true when metadata is configured
    • rowCount

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

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

      public List<List<String>> rows()
      Returns an immutable snapshot of all rows. Each row is immutable and header-aligned.
      Returns:
      an immutable snapshot of the current rows
    • 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)
      Appends a semicolon-delimited CSV row.

      CSV quoting is parsed, so "a;b";c represents two values. The parsed row must have exactly the same number of values as the configured header.

      Parameters:
      semicolonSeparatedRow - the complete semicolon-delimited CSV row
    • append

      public void append(String[] orderedValues)
      Appends a complete positional row from an array.
      Parameters:
      orderedValues - the values in configured header order
    • append

      public void append(Collection<String> orderedValues)
      Appends a complete positional row from a collection.
      Parameters:
      orderedValues - the values in configured header order
    • appendValues

      public void appendValues(Object... orderedValues)
      Appends a complete positional row containing arbitrary values converted with String.valueOf(Object). Nulls produce empty cells.
      Parameters:
      orderedValues - the values in configured header order
    • append

      public void append(Map<String,?> valuesByHeader)
      Appends a sparse row addressed by canonical header keys or configured output names. Missing columns are written as empty cells; unknown columns are rejected.
      Parameters:
      valuesByHeader - values keyed by canonical header key or configured output name
    • append

      public void append(io.github.mrtyldr.datev.core.DatevColumn<?>... columns)
      Appends a sparse formatted row.

      This varargs overload complements append(Collection) because Java erases Collection<String> and Collection<DatevColumn<?>> to the same signature.

      Parameters:
      columns - the formatted columns to place by header identifier
    • append

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

      The Iterable parameter deliberately differs from the positional Collection<String> overload after Java generic type erasure. A Collection<DatevColumn<?>> can therefore still be passed directly to append(...) with compile-time type safety.

      Parameters:
      columns - the formatted columns to place by header identifier
    • appendColumns

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

      Formatting and validation complete before the row is added, so a failure never leaves a partial row behind.

      Parameters:
      columns - the formatted columns to place by header identifier
    • writeTo

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

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

      public void writeTo(Writer output)
      Writes the header and all current rows to a character writer without closing it.
      Parameters:
      output - the caller-owned destination writer
    • toByteArray

      public byte[] toByteArray()
      Returns the complete CSV as bytes in charset().
      Returns:
      the complete CSV encoded with this file's charset
    • toCsvString

      public String toCsvString()
      Returns the complete CSV as characters, primarily for inspection and testing.
      Returns:
      the complete CSV text