Class DatevFile
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 ClassesModifier and TypeClassDescriptionstatic final classBuilds a file with immutable header configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetThe default character set accepted by DATEV accounting imports.static final charThe separator required by the DATEV CSV format.static final StringThe record separator required by the DATEV CSV format.static final intMaximum number of booking records in one DATEV Buchungsstapel file. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(io.github.mrtyldr.datev.core.DatevColumn<?>... columns) Appends a sparse formatted row.voidAppends a sparse formatted row from an iterable of columns.voidAppends a semicolon-delimited CSV row.voidAppends a complete positional row from an array.voidappend(Collection<String> orderedValues) Appends a complete positional row from a collection.voidAppends a sparse row addressed by canonical header keys or configured output names.voidappendColumns(Collection<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns) Appends a sparse formatted row from a collection of columns.voidappendValues(Object... orderedValues) Appends a complete positional row containing arbitrary values converted withString.valueOf(Object).static DatevFile.Builderbuilder()Starts a builder with the current default DATEV Buchungsstapel header.static DatevFile.Builderbuilder(io.github.mrtyldr.datev.core.DatevHeader header) Starts a builder with a custom or preconfigured header.charset()Returns the charset used bywriteTo(OutputStream).io.github.mrtyldr.datev.core.DatevHeaderheader()Returns this file's immutable header definition.headers()Returns the output header names in their configured order.booleanReturns whether convenience output contains a complete EXTF management record.booleanisEmpty()Returns whether no data rows have been appended.iterator()Returns an iterator over an immutable snapshot of the current rows.Optional<io.github.mrtyldr.datev.core.DatevMetadata>metadata()Returns the optional EXTF management-record metadata.introwCount()Returns the number of appended rows.rows()Returns an immutable snapshot of all rows.byte[]Returns the complete CSV as bytes incharset().Returns the complete CSV as characters, primarily for inspection and testing.io.github.mrtyldr.datev.core.DatevValidationModeReturns the configured semantic validation mode.static DatevFileCreates a file with the current default DATEV Buchungsstapel header and writer settings.static DatevFilewithDefaults(io.github.mrtyldr.datev.core.DatevMetadata metadata) Creates a complete Buchungsstapel v13 file with a typed EXTF management record.static DatevFilewithHeader(io.github.mrtyldr.datev.core.DatevHeader header) Creates a file with an already configured immutable header.static DatevFilewithHeader(String semicolonSeparatedHeader) Creates a file with a semicolon-separated custom header.static DatevFilewithHeader(String[] header) Creates a file with a custom header.static DatevFilewithHeader(List<String> header) Creates a file with a custom header.voidwrite(OutputStream output) Alias forwriteTo(OutputStream).voidwriteTo(OutputStream output) Writes the header and all current rows to an output stream without closing it.voidWrites 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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_DELIMITER
public static final char DEFAULT_DELIMITERThe separator required by the DATEV CSV format.- See Also:
-
DEFAULT_LINE_SEPARATOR
The record separator required by the DATEV CSV format.- See Also:
-
DEFAULT_CHARSET
The default character set accepted by DATEV accounting imports. -
MAX_DATA_ROWS
public static final int MAX_DATA_ROWSMaximum number of booking records in one DATEV Buchungsstapel file.- See Also:
-
-
Method Details
-
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
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
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
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
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
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
Starts a builder with the current default DATEV Buchungsstapel header.- Returns:
- a new builder using the default header
-
builder
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
Returns the output header names in their configured order.- Returns:
- the ordered, immutable output header names
-
charset
Returns the charset used bywriteTo(OutputStream).- Returns:
- the output charset
-
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:
truewhen 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:
truewhen this file contains no data rows
-
rows
Returns an immutable snapshot of all rows. Each row is immutable and header-aligned.- Returns:
- an immutable snapshot of the current rows
-
iterator
Returns an iterator over an immutable snapshot of the current rows. -
append
Appends a semicolon-delimited CSV row.CSV quoting is parsed, so
"a;b";crepresents 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
Appends a complete positional row from an array.- Parameters:
orderedValues- the values in configured header order
-
append
Appends a complete positional row from a collection.- Parameters:
orderedValues- the values in configured header order
-
appendValues
Appends a complete positional row containing arbitrary values converted withString.valueOf(Object). Nulls produce empty cells.- Parameters:
orderedValues- the values in configured header order
-
append
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 erasesCollection<String>andCollection<DatevColumn<?>>to the same signature.- Parameters:
columns- the formatted columns to place by header identifier
-
append
Appends a sparse formatted row from an iterable of columns.The
Iterableparameter deliberately differs from the positionalCollection<String>overload after Java generic type erasure. ACollection<DatevColumn<?>>can therefore still be passed directly toappend(...)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
Writes the header and all current rows to an output stream without closing it.- Parameters:
output- the caller-owned destination stream
-
write
Alias forwriteTo(OutputStream).- Parameters:
output- the caller-owned destination stream
-
writeTo
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 incharset().- Returns:
- the complete CSV encoded with this file's charset
-
toCsvString
Returns the complete CSV as characters, primarily for inspection and testing.- Returns:
- the complete CSV text
-