Package org.supercsv.io
Class CsvListReader
- java.lang.Object
-
- org.supercsv.io.AbstractCsvReader
-
- org.supercsv.io.CsvListReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.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.- Author:
- Kasper B. Graversen, James Bassett
-
-
Constructor Summary
Constructors Constructor Description CsvListReader(java.io.Reader reader, CsvPreference preferences)
Constructs a new CsvListReader with the supplied Reader and CSV preferences.CsvListReader(ITokenizer tokenizer, CsvPreference preferences)
Constructs a new CsvListReader with the supplied (custom) Tokenizer and CSV preferences.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.Object>
executeProcessors(CellProcessor... processors)
Executes the supplied cell processors on the last row of CSV that was read.java.util.List<java.lang.String>
read()
Reads a row of a CSV file and returns a List of Strings containing each column.java.util.List<java.lang.Object>
read(CellProcessor... processors)
Reads a row of a CSV file and returns a List of Objects containing each column.-
Methods inherited from class org.supercsv.io.AbstractCsvReader
close, executeProcessors, get, getColumns, getHeader, getLineNumber, getPreferences, getRowNumber, getUntokenizedRow, length, readRow
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.supercsv.io.ICsvReader
get, getHeader, getLineNumber, getRowNumber, getUntokenizedRow, length
-
-
-
-
Constructor Detail
-
CsvListReader
public CsvListReader(java.io.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 readerpreferences
- the CSV preferences- Throws:
java.lang.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 tokenizerpreferences
- the CSV preferences- Throws:
java.lang.NullPointerException
- if tokenizer or preferences are null
-
-
Method Detail
-
read
public java.util.List<java.lang.String> read() throws java.io.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 ofICsvListReader.read(CellProcessor...)
because your CSV file has a variable number of columns, then you can call theICsvListReader.executeProcessors(CellProcessor...)
method after callingICsvListReader.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 interfaceICsvListReader
- Returns:
- the List of columns, or null if EOF
- Throws:
java.io.IOException
- if an I/O error occurred
-
read
public java.util.List<java.lang.Object> read(CellProcessor... processors) throws java.io.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 interfaceICsvListReader
- 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:
java.io.IOException
- if an I/O error occurred
-
executeProcessors
public java.util.List<java.lang.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 useICsvListReader.read()
instead ofICsvListReader.read(CellProcessor...)
.- Specified by:
executeProcessors
in interfaceICsvListReader
- 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
-
-