public abstract class AbstractCsvReader extends Object implements ICsvReader
Constructor and Description |
---|
AbstractCsvReader(ITokenizer tokenizer,
CsvPreference preferences)
Constructs a new AbstractCsvReader, using a custom
Tokenizer (which should have already been set
up with the Reader, CsvPreference, and CsvContext). |
AbstractCsvReader(Reader reader,
CsvPreference preferences)
Constructs a new AbstractCsvReader, using the default
Tokenizer . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the Tokenizer and its associated Reader.
|
protected List<Object> |
executeProcessors(List<Object> processedColumns,
CellProcessor[] processors)
Executes the supplied cell processors on the last row of CSV that was read and populates the supplied List of
processed columns.
|
String |
get(int n)
Get column N of the current line (column indexes begin at 1).
|
protected List<String> |
getColumns()
Gets the tokenized columns.
|
String[] |
getHeader(boolean firstLineCheck)
This method is used to get an optional header of the CSV file and move the file cursor to the first row
containing data (the second row from the top).
|
int |
getLineNumber()
Gets the current position in the file, where the first line of the file is line number 1.
|
protected CsvPreference |
getPreferences()
Gets the preferences.
|
int |
getRowNumber()
Gets the current row number (i.e.
|
String |
getUntokenizedRow()
Returns the untokenized CSV row that was just read (which can potentially span multiple lines in the file).
|
int |
length()
Returns the length (i.e.
|
protected boolean |
readRow()
Calls the tokenizer to read a CSV row.
|
public AbstractCsvReader(Reader reader, CsvPreference preferences)
Tokenizer
.reader
- the readerpreferences
- the CSV preferencesNullPointerException
- if reader or preferences are nullpublic AbstractCsvReader(ITokenizer tokenizer, CsvPreference preferences)
Tokenizer
(which should have already been set
up with the Reader, CsvPreference, and CsvContext). This constructor should only be used if the default Tokenizer
doesn't provide the required functionality.tokenizer
- the tokenizerpreferences
- the CSV preferencesNullPointerException
- if tokenizer or preferences are nullpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public String get(int n)
get
in interface ICsvReader
n
- the index of the column to getpublic String[] getHeader(boolean firstLineCheck) throws IOException
nameMapping
array for read operations.getHeader
in interface ICsvReader
firstLineCheck
- if true, ensures that this method is only called when reading the first line (as that's where the
header is meant to be)IOException
- if an I/O exception occurspublic int getLineNumber()
getLineNumber
in interface ICsvReader
public String getUntokenizedRow()
getUntokenizedRow
in interface ICsvReader
public int getRowNumber()
getRowNumber
in interface ICsvReader
public int length()
length
in interface ICsvReader
protected List<String> getColumns()
protected CsvPreference getPreferences()
protected boolean readRow() throws IOException
getColumns()
.IOException
- when an IOException occursSuperCsvException
- on errors in parsing the inputprotected List<Object> executeProcessors(List<Object> processedColumns, CellProcessor[] processors)
processedColumns
- the List to populate with processed columnsprocessors
- the cell processorsNullPointerException
- if processedColumns or processors is nullSuperCsvConstraintViolationException
- if a CellProcessor constraint failedSuperCsvException
- if the wrong number of processors are supplied, or CellProcessor execution failedCopyright © 2007–2015 Super CSV. All rights reserved.