Class CsvListReader

All Implemented Interfaces:
Closeable, AutoCloseable, ICsvListReader, ICsvReader

public class CsvListReader extends AbstractCsvReader implements ICsvListReader
CsvListReader is a simple reader that reads a row from a CSV file into a List of Strings.
  • Constructor Details

    • CsvListReader

      public CsvListReader(Reader reader, CsvPreference preferences)
      Constructs a new CsvListReader with the supplied Reader and CSV preferences. Note that the reader will be wrapped in a BufferedReader before accessed.
      Parameters:
      reader - the reader
      preferences - the CSV preferences
      Throws:
      NullPointerException - if reader or preferences are null
    • CsvListReader

      public CsvListReader(ITokenizer tokenizer, CsvPreference preferences)
      Constructs a new CsvListReader with the supplied (custom) Tokenizer and CSV preferences. The tokenizer should be set up with the Reader (CSV input) and CsvPreference beforehand.
      Parameters:
      tokenizer - the tokenizer
      preferences - the CSV preferences
      Throws:
      NullPointerException - if tokenizer or preferences are null
  • Method Details

    • read

      public List<String> read() throws IOException
      Reads a row of a CSV file and returns a List of Strings containing each column. If you are forced to use this method instead of ICsvListReader.read(CellProcessor...) because your CSV file has a variable number of columns, then you can call the ICsvListReader.executeProcessors(CellProcessor...) method after calling ICsvListReader.read() to execute the cell processors manually (after determining the number of columns read in and which cell processors to use).
      Specified by:
      read in interface ICsvListReader
      Returns:
      the List of columns, or null if EOF
      Throws:
      IOException - if an I/O error occurred
    • read

      public List<Object> read(CellProcessor... processors) throws IOException
      Reads a row of a CSV file and returns a List of Objects containing each column. The data can be further processed by cell processors (each element in the processors array corresponds with a CSV column). A null entry in the processors array indicates no further processing is required (the unprocessed String value will be added to the List). Prior to version 2.0.0 this method returned a List of Strings.
      Specified by:
      read in interface ICsvListReader
      Parameters:
      processors - an array of CellProcessors used to further process data before it is added to the List (each element in the processors array corresponds with a CSV column - the number of processors should match the number of columns). A null entry indicates no further processing is required (the unprocessed String value will be added to the List).
      Returns:
      the List of columns, or null if EOF
      Throws:
      IOException - if an I/O error occurred
    • executeProcessors

      public List<Object> executeProcessors(CellProcessor... processors)
      Executes the supplied cell processors on the last row of CSV that was read. This should only be used when the number of CSV columns is unknown before the row is read, and you are forced to use ICsvListReader.read() instead of ICsvListReader.read(CellProcessor...).
      Specified by:
      executeProcessors in interface ICsvListReader
      Parameters:
      processors - an array of CellProcessors used to further process the last row of CSV data that was read (each element in the processors array corresponds with a CSV column - the number of processors should match the number of columns). A null entry indicates no further processing is required (the unprocessed String value will be added to the List).
      Returns:
      the List of processed columns