Class CsvRowCollector
java.lang.Object
de.fraunhofer.iosb.ilt.frostserver.plugin.format.csv.tools.CsvRowCollector
Collects all elements for a single row in a CSV file.
First, each element is registered by its header name. This returns the index
of the element. After this, for each row, each element is collected in order.
If one or more elements are skipped, the elements set to null. Finally, the
entire row is flushed to the CSVPrinter, and the collector is reset.
- Author:
- scf
-
Constructor Summary
ConstructorsConstructorDescriptionCsvRowCollector(org.apache.commons.csv.CSVPrinter printer) Create a new Collector. -
Method Summary
Modifier and TypeMethodDescriptionvoidcollectEntry(int idx, Object value) Collect a new value for the element with the given index.voidflush()Flush the row to the CSVPrinter, and reset the collector.intregisterHeader(String headerName) Register a new element in the collector.
-
Constructor Details
-
CsvRowCollector
public CsvRowCollector(org.apache.commons.csv.CSVPrinter printer) Create a new Collector.- Parameters:
printer- The printer to write the collected elements to.
-
-
Method Details
-
registerHeader
Register a new element in the collector. The index of the new element is returned. This index must be used when collecting the values of this element.- Parameters:
headerName- The header name of the new element.- Returns:
- The index of the new element.
-
collectEntry
Collect a new value for the element with the given index.- Parameters:
idx- The index of the element.value- The value of the element for the current row.
-
flush
Flush the row to the CSVPrinter, and reset the collector.- Throws:
IOException- If there is a problem with the printer.
-