Class DatevStreamWriter
- All Implemented Interfaces:
AutoCloseable
Attach a DatevMetadata through builder() to emit the mandatory EXTF
management record before the heading and produce a complete, importable Buchungsstapel file.
Both records are written when the writer is constructed.
Each append is fully aligned, formatted, structurally checked, optionally validated and
serialized in row-local memory before output begins. Every completed record is then handed to
the destination immediately; this writer does not batch records or retain serialization buffers
between appends. Successfully written rows are discarded, so library-managed working memory is
proportional to one row instead of the total row count. Byte-stream output uses one temporary
encoded byte array per record. Callers decide whether the destination itself should buffer those
writes by supplying, for example, a BufferedOutputStream.
The supplied output remains caller-owned: during normal completion close() flushes it
but does not close it. After a destination failure, close does not retry a flush. Byte-stream
factories emit Windows-1252 directly; callers supplying a character Writer remain
responsible for its eventual byte encoding.
Validation and formatting failures leave the output unchanged and the writer reusable. An I/O failure can occur after a destination has accepted part of a record, so physical rollback cannot be guaranteed; the writer becomes terminal after any destination failure. Instances are mutable, forward-only and not thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigures a streaming writer, including the optional EXTF management record. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(io.github.mrtyldr.datev.core.DatevColumn<?>... columns) Writes a sparse formatted row addressed by exact official heading names.voidWrites formatted columns from an iterable.voidParses and writes exactly one strict semicolon-delimited CSV record.voidWrites a complete positional row from a defensively copied array.voidappend(Collection<String> orderedValues) Writes a complete positional row from a defensively copied collection.voidWrites a sparse row addressed by exact official heading names.voidappendColumns(Collection<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns) Writes a sparse formatted row from a collection.voidappendValues(Object... orderedValues) Writes a complete positional row after converting non-null values withString.valueOf(Object).static DatevStreamWriter.Builderbuilder()Creates a builder for the current v13 schema.static DatevStreamWriter.Builderbuilder(io.github.mrtyldr.datev.core.DatevSchema schema) Creates a builder for an explicit fixed schema.charset()Returns the byte-output charset.voidclose()Flushes completed records and makes this writer terminal without closing the caller-owned destination.voidflush()Flushes completed records without closing the caller-owned destination.static DatevStreamWriterforSchema(io.github.mrtyldr.datev.core.DatevSchema schema, OutputStream output) Starts an unvalidated writer for one fixed schema on a caller-owned byte stream.static DatevStreamWriterforSchema(io.github.mrtyldr.datev.core.DatevSchema schema, OutputStream output, BiConsumer<Integer, List<String>> validator) Starts a validated writer for one fixed schema on a caller-owned byte stream.static DatevStreamWriterStarts an unvalidated writer for one fixed schema on a caller-owned character writer.static DatevStreamWriterforSchema(io.github.mrtyldr.datev.core.DatevSchema schema, Writer output, BiConsumer<Integer, List<String>> validator) Starts a validated writer for one fixed schema on a caller-owned character writer.headers()Returns the immutable official headings in output order.booleanReturns whether the output contains the mandatory EXTF management record.booleanisEmpty()Returns whether no booking row has been successfully written.static DatevStreamWriterlegacyV12(OutputStream output) Starts an unvalidated legacy-v12 writer on a caller-owned byte stream.static DatevStreamWriterlegacyV12(OutputStream output, BiConsumer<Integer, List<String>> validator) Starts a validated legacy-v12 writer on a caller-owned byte stream.static DatevStreamWriterStarts an unvalidated legacy-v12 writer on a caller-owned character writer.static DatevStreamWriterStarts a validated legacy-v12 writer on a caller-owned character writer.Optional<io.github.mrtyldr.datev.core.DatevMetadata>metadata()Returns the EXTF management record written before the heading, if any.introwCount()Returns the number of booking rows successfully handed to the destination.io.github.mrtyldr.datev.core.DatevSchemaschema()Returns the fixed schema selected for this output.Returns the configured optional validator.static DatevStreamWriterwithDefaults(OutputStream output) Starts an unvalidated current-v13 writer on a caller-owned byte stream.static DatevStreamWriterwithDefaults(OutputStream output, BiConsumer<Integer, List<String>> validator) Starts a validated current-v13 writer on a caller-owned byte stream.static DatevStreamWriterwithDefaults(Writer output) Starts an unvalidated current-v13 writer on a caller-owned character writer.static DatevStreamWriterwithDefaults(Writer output, BiConsumer<Integer, List<String>> validator) Starts a validated current-v13 writer on a caller-owned character writer.
-
Method Details
-
builder
Creates a builder for the current v13 schema.- Returns:
- a new builder
-
builder
Creates a builder for an explicit fixed schema.- Parameters:
schema- the fixed schema to use- Returns:
- a new builder
-
withDefaults
Starts an unvalidated current-v13 writer on a caller-owned byte stream.- Parameters:
output- destination receiving strict Windows-1252 bytes- Returns:
- a new forward-only writer whose column heading has been written
-
withDefaults
public static DatevStreamWriter withDefaults(OutputStream output, BiConsumer<Integer, List<String>> validator) Starts a validated current-v13 writer on a caller-owned byte stream.- Parameters:
output- destination receiving strict Windows-1252 bytesvalidator- validator invoked before each row write- Returns:
- a new forward-only writer whose column heading has been written
-
withDefaults
Starts an unvalidated current-v13 writer on a caller-owned character writer.- Parameters:
output- destination character writer- Returns:
- a new forward-only writer whose column heading has been written
-
withDefaults
public static DatevStreamWriter withDefaults(Writer output, BiConsumer<Integer, List<String>> validator) Starts a validated current-v13 writer on a caller-owned character writer.- Parameters:
output- destination character writervalidator- validator invoked before each row write- Returns:
- a new forward-only writer whose column heading has been written
-
legacyV12
Starts an unvalidated legacy-v12 writer on a caller-owned byte stream.- Parameters:
output- destination receiving strict Windows-1252 bytes- Returns:
- a new forward-only writer whose column heading has been written
-
legacyV12
public static DatevStreamWriter legacyV12(OutputStream output, BiConsumer<Integer, List<String>> validator) Starts a validated legacy-v12 writer on a caller-owned byte stream.- Parameters:
output- destination receiving strict Windows-1252 bytesvalidator- validator invoked before each row write- Returns:
- a new forward-only writer whose column heading has been written
-
legacyV12
Starts an unvalidated legacy-v12 writer on a caller-owned character writer.- Parameters:
output- destination character writer- Returns:
- a new forward-only writer whose column heading has been written
-
legacyV12
public static DatevStreamWriter legacyV12(Writer output, BiConsumer<Integer, List<String>> validator) Starts a validated legacy-v12 writer on a caller-owned character writer.- Parameters:
output- destination character writervalidator- validator invoked before each row write- Returns:
- a new forward-only writer whose column heading has been written
-
forSchema
public static DatevStreamWriter forSchema(io.github.mrtyldr.datev.core.DatevSchema schema, OutputStream output) Starts an unvalidated writer for one fixed schema on a caller-owned byte stream.- Parameters:
schema- fixed DATEV schemaoutput- destination receiving strict Windows-1252 bytes- Returns:
- a new forward-only writer whose column heading has been written
-
forSchema
public static DatevStreamWriter forSchema(io.github.mrtyldr.datev.core.DatevSchema schema, OutputStream output, BiConsumer<Integer, List<String>> validator) Starts a validated writer for one fixed schema on a caller-owned byte stream.- Parameters:
schema- fixed DATEV schemaoutput- destination receiving strict Windows-1252 bytesvalidator- validator invoked before each row write- Returns:
- a new forward-only writer whose column heading has been written
-
forSchema
public static DatevStreamWriter forSchema(io.github.mrtyldr.datev.core.DatevSchema schema, Writer output) Starts an unvalidated writer for one fixed schema on a caller-owned character writer.- Parameters:
schema- fixed DATEV schemaoutput- destination character writer- Returns:
- a new forward-only writer whose column heading has been written
-
forSchema
public static DatevStreamWriter forSchema(io.github.mrtyldr.datev.core.DatevSchema schema, Writer output, BiConsumer<Integer, List<String>> validator) Starts a validated writer for one fixed schema on a caller-owned character writer.- Parameters:
schema- fixed DATEV schemaoutput- destination character writervalidator- validator invoked before each row write- Returns:
- a new forward-only writer whose column heading has been written
-
schema
public io.github.mrtyldr.datev.core.DatevSchema schema()Returns the fixed schema selected for this output.- Returns:
- selected v12 or v13 schema
-
headers
Returns the immutable official headings in output order.- Returns:
- fixed ordered headings
-
charset
Returns the byte-output charset.- Returns:
- Windows-1252
-
validator
Returns the configured optional validator.- Returns:
- configured format-version/row consumer, if any
-
metadata
Returns the EXTF management record written before the heading, if any.- Returns:
- the configured metadata
-
isCompleteExtf
public boolean isCompleteExtf()Returns whether the output contains the mandatory EXTF management record.- Returns:
trueif metadata was configured
-
rowCount
public int rowCount()Returns the number of booking rows successfully handed to the destination.- Returns:
- committed row count, excluding the heading
-
isEmpty
public boolean isEmpty()Returns whether no booking row has been successfully written.- Returns:
trueuntil the first successful row write
-
append
Parses and writes exactly one strict semicolon-delimited CSV record.- Parameters:
semicolonSeparatedRow- exactly one complete CSV row
-
append
Writes a complete positional row from a defensively copied array.- Parameters:
orderedValues- values in fixed heading order
-
append
Writes a complete positional row from a defensively copied collection.- Parameters:
orderedValues- values in fixed heading order
-
appendValues
Writes a complete positional row after converting non-null values withString.valueOf(Object).- Parameters:
orderedValues- values in fixed heading order
-
append
Writes a sparse row addressed by exact official heading names.- Parameters:
valuesByHeader- values addressed by exact official headings
-
append
public void append(io.github.mrtyldr.datev.core.DatevColumn<?>... columns) Writes a sparse formatted row addressed by exact official heading names.- Parameters:
columns- columns to align by heading
-
append
Writes formatted columns from an iterable.- Parameters:
columns- columns to align by heading
-
appendColumns
public void appendColumns(Collection<? extends io.github.mrtyldr.datev.core.DatevColumn<?>> columns) Writes a sparse formatted row from a collection.- Parameters:
columns- columns to align by heading
-
flush
public void flush()Flushes completed records without closing the caller-owned destination.- Throws:
UncheckedIOException- if the destination rejects the flush
-
close
public void close()Flushes completed records and makes this writer terminal without closing the caller-owned destination.Repeated calls have no effect. If a previous destination operation failed, this method does not retry flushing potentially partial output, and it does not close the destination either.
- Specified by:
closein interfaceAutoCloseable- Throws:
UncheckedIOException- if the destination rejects the flush
-