Class CsvRowCollector
- java.lang.Object
-
- de.fraunhofer.iosb.ilt.frostserver.plugin.format.csv.tools.CsvRowCollector
-
public class CsvRowCollector extends Object
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
Constructors Constructor Description CsvRowCollector(org.apache.commons.csv.CSVPrinter printer)Create a new Collector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcollectEntry(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.
-
-
-
Method Detail
-
registerHeader
public int registerHeader(String headerName)
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
public void collectEntry(int idx, Object value)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
public void flush() throws IOExceptionFlush the row to the CSVPrinter, and reset the collector.- Throws:
IOException- If there is a problem with the printer.
-
-