Class 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 Detail

      • CsvRowCollector

        public CsvRowCollector​(org.apache.commons.csv.CSVPrinter printer)
        Create a new Collector.
        Parameters:
        printer - The printer to write the collected elements to.
    • 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 IOException
        Flush the row to the CSVPrinter, and reset the collector.
        Throws:
        IOException - If there is a problem with the printer.