| Modifier and Type | Field and Description |
|---|---|
| protected BufferedReader | |
| pack-priv static final int | |
| public static final boolean | |
| public static final int | DEFAULT_MULTILINE_LIMIT
The default limit for the number of lines in a multiline record. |
| public static final int | DEFAULT_SKIP_LINES
The default line to start reading. |
| public static final boolean | |
| protected Locale | |
| protected boolean | |
| protected boolean | |
| protected LineReader | |
| protected long | |
| protected boolean | |
| private final LineValidatorAggregator | |
| private static final int | |
| protected int | |
| protected ICSVParser | |
| protected static final List | |
| protected String[] | |
| protected final Queue | |
| public static final int | |
| protected long | |
| private final RowProcessor | |
| private final RowValidatorAggregator | |
| protected int | |
| protected boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| pack-priv | CSVReader(Reader
The reader to an underlying CSV source reader, int The number of lines to skip before reading line, ICSVParser The parser to use to parse input icsvParser, boolean True to keep carriage returns in data read, false otherwise keepCR, boolean True to verify reader before each read, false otherwise verifyReader, int Allow the user to define the limit to the number of lines in a multiline record. Less than one means no limit. multilineLimit, Locale Set the locale for error messages. If null, the default locale is used. errorLocale, LineValidatorAggregator contains all the custom defined line validators. lineValidatorAggregator, RowValidatorAggregator contains all the custom defined row validators. rowValidatorAggregator, RowProcessor Custom row processor to run on all columns on a csv record. rowProcessor)Constructs CSVReader with supplied CSVParser. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| protected String[] | Returns: String array with union of the buffer and lastRead arrays.Previous data read for this record buffer, String[] Latest data read for this record. lastRead)For multi-line records this method combines the current result with the result from previous read(s). |
| private String[] | Returns: The next line of inputWhether the line returned should be popped off the queue
of input. If this is popLine, boolean true, this method consumes
the line and further calls will return the next line of
input. If false, the line returned stays in the
queue and further calls to this method will return the
same line again.Whether all user-supplied validators should be run. validate)Reads a line of input, popping or validating as desired. |
| public long | Returns: The number of lines read by the reader (including skipped lines).This method returns the number of lines that has been read from the reader passed into the CSVReader. |
| public int | Returns: The maximum number of lines allowed in a multiline record.Only useful for tests. |
| protected String | Returns: The next line from the file without trailing newline, or null if there is no more input.Reads the next line from the file. |
| public ICSVParser | |
| public long | Returns: The number of records (array of Strings[]) read by the reader.Used for debugging purposes, this method returns the number of records that has been read from the CSVReader. |
| public int | Returns: The number of lines in the CSV file to skip before processing.Returns the number of lines in the CSV file to skip before processing. |
| protected boolean | Returns: true if the reader can no longer be read fromChecks to see if the file is closed. |
| public Iterator | Returns: A String[] iterator.Implements java. Creates an Iterator for processing the CSV data. |
| public boolean | Returns: True if reader will keep carriage returns, false otherwise.Returns if the reader will keep carriage returns found in data or remove them. |
| public String[] | Returns: The next line from the input, ornull if there are no
more linesReturns the next line from the input without removing it from the CSVReader and not running any validators. |
| private void | |
| public List | Returns: A List of String[], with each String[] representing a line of the file.Reads the entire file into a List with each element being a String[] of tokens. |
| public String[] | Returns: A string array with each comma-separated element as a separate entry, or null if there is no more input.Reads the next line from the buffer and converts to a string array. |
| public String[] | Returns: A string array with each comma-separated element as a separate entry, or null if there is no more input.Reads the next line from the buffer and converts to a string array without running the custom defined validators. |
| public void | setErrorLocale(Locale
Locale for error messages. If null, the default locale
is used. errorLocale)Sets the locale for all error messages. |
| public void | |
| private void | validateLine(long
The line number for error messages lastSuccessfulLineRead, String The input to be validated nextLine)Runs all line validators on the input. |
| protected void | validateResult(String[]
The result of the read operation result, long Line number that the row started on lineStartOfRow)Increments the number of records read if the result passed in is not null. |
| public boolean | Returns: True if CSVReader will verify the reader before reads. False otherwise.Returns if the CSVReader will verify the reader before each read. |
| br | back to summary |
|---|---|
| protected BufferedReader br | |
| CONTEXT_MULTILINE_EXCEPTION_MESSAGE_SIZE | back to summary |
|---|---|
| pack-priv static final int CONTEXT_MULTILINE_EXCEPTION_MESSAGE_SIZE | |
| DEFAULT_KEEP_CR | back to summary |
|---|---|
| public static final boolean DEFAULT_KEEP_CR | |
| DEFAULT_MULTILINE_LIMIT | back to summary |
|---|---|
| public static final int DEFAULT_MULTILINE_LIMIT The default limit for the number of lines in a multiline record. Less than one means no limit. | |
| DEFAULT_SKIP_LINES | back to summary |
|---|---|
| public static final int DEFAULT_SKIP_LINES The default line to start reading. | |
| DEFAULT_VERIFY_READER | back to summary |
|---|---|
| public static final boolean DEFAULT_VERIFY_READER | |
| errorLocale | back to summary |
|---|---|
| protected Locale errorLocale | |
| hasNext | back to summary |
|---|---|
| protected boolean hasNext | |
| keepCR | back to summary |
|---|---|
| protected boolean keepCR | |
| lineReader | back to summary |
|---|---|
| protected LineReader lineReader | |
| linesRead | back to summary |
|---|---|
| protected long linesRead | |
| linesSkipped | back to summary |
|---|---|
| protected boolean linesSkipped | |
| lineValidatorAggregator | back to summary |
|---|---|
| private final LineValidatorAggregator lineValidatorAggregator | |
| MAX_WIDTH | back to summary |
|---|---|
| private static final int MAX_WIDTH | |
| multilineLimit | back to summary |
|---|---|
| protected int multilineLimit | |
| parser | back to summary |
|---|---|
| protected ICSVParser parser | |
| PASSTHROUGH_EXCEPTIONS | back to summary |
|---|---|
| protected static final List<Class<? extends IOException>> PASSTHROUGH_EXCEPTIONS | |
| peekedLine | back to summary |
|---|---|
| protected String[] peekedLine | |
| peekedLines | back to summary |
|---|---|
| protected final Queue<OrderedObject<String>> peekedLines | |
| READ_AHEAD_LIMIT | back to summary |
|---|---|
| public static final int READ_AHEAD_LIMIT | |
| recordsRead | back to summary |
|---|---|
| protected long recordsRead | |
| rowProcessor | back to summary |
|---|---|
| private final RowProcessor rowProcessor | |
| rowValidatorAggregator | back to summary |
|---|---|
| private final RowValidatorAggregator rowValidatorAggregator | |
| skipLines | back to summary |
|---|---|
| protected int skipLines | |
| verifyReader | back to summary |
|---|---|
| protected boolean verifyReader | |
| CSVReader | back to summary |
|---|---|
| public CSVReader(Reader reader) Constructs CSVReader using defaults for all parameters.
| |
| CSVReader | back to summary |
|---|---|
| pack-priv CSVReader(Reader reader, int line, ICSVParser icsvParser, boolean keepCR, boolean verifyReader, int multilineLimit, Locale errorLocale, LineValidatorAggregator lineValidatorAggregator, RowValidatorAggregator rowValidatorAggregator, RowProcessor rowProcessor) Constructs CSVReader with supplied CSVParser. This constructor sets all necessary parameters for CSVReader, and intentionally has package access so only the builder can use it.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Closes the underlying reader.
| |
| combineResultsFromMultipleReads | back to summary |
|---|---|
| protected String[] combineResultsFromMultipleReads(String[] buffer, String[] lastRead) For multi-line records this method combines the current result with the result from previous read(s). | |
| flexibleRead | back to summary |
|---|---|
| private String[] flexibleRead(boolean popLine, boolean validate) throws IOException, CsvValidationException Reads a line of input, popping or validating as desired.
| |
| getLinesRead | back to summary |
|---|---|
| public long getLinesRead() This method returns the number of lines that has been read from the reader passed into the CSVReader. Given the following data: First line in the file some other descriptive line a,b,c a,"b\nb",c
With a CSVReader constructed like so:
| |
| getMultilineLimit | back to summary |
|---|---|
| public int getMultilineLimit() Only useful for tests.
| |
| getNextLine | back to summary |
|---|---|
| protected String getNextLine() throws IOException Reads the next line from the file.
| |
| getParser | back to summary |
|---|---|
public ICSVParser getParser()
| |
| getRecordsRead | back to summary |
|---|---|
| public long getRecordsRead() Used for debugging purposes, this method returns the number of records that has been read from the CSVReader. Given the following data: First line in the file some other descriptive line a,b,c a,"b\nb",c
With a CSVReader constructed like so: An example of this is in the linesAndRecordsRead() test in CSVReaderTest.
| |
| getSkipLines | back to summary |
|---|---|
| public int getSkipLines() Returns the number of lines in the CSV file to skip before processing. This is useful when there are miscellaneous data at the beginning of a file.
| |
| isClosed | back to summary |
|---|---|
| protected boolean isClosed() throws IOException Checks to see if the file is closed. Certain
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Creates an Iterator for processing the CSV data. | |
| keepCarriageReturns | back to summary |
|---|---|
| public boolean keepCarriageReturns() Returns if the reader will keep carriage returns found in data or remove them.
| |
| peek | back to summary |
|---|---|
| public String[] peek() throws IOException Returns the next line from the input without removing it from the
CSVReader and not running any validators.
Subsequent calls to this method will continue to return the same line
until a call is made to
| |
| primeNextRecord | back to summary |
|---|---|
| private void primeNextRecord() throws IOException Reads the next line from the buffer and converts to a string array.
The results are stored in
| |
| readAll | back to summary |
|---|---|
| public List Reads the entire file into a List with each element being a String[] of
tokens.
Since the current implementation returns a
| |
| readNext | back to summary |
|---|---|
| public String[] readNext() throws IOException, CsvValidationException Reads the next line from the buffer and converts to a string array.
| |
| readNextSilently | back to summary |
|---|---|
| public String[] readNextSilently() throws IOException Reads the next line from the buffer and converts to a string array without running the custom defined validators. This is called by the bean readers when reading the header.
| |
| setErrorLocale | back to summary |
|---|---|
| public void setErrorLocale(Locale errorLocale) Sets the locale for all error messages.
| |
| skip | back to summary |
|---|---|
| public void skip(int numberOfLinesToSkip) throws IOException Skip a given number of lines.
| |
| validateLine | back to summary |
|---|---|
| private void validateLine(long lastSuccessfulLineRead, String nextLine) throws CsvValidationException Runs all line validators on the input.
| |
| validateResult | back to summary |
|---|---|
| protected void validateResult(String[] result, long lineStartOfRow) throws CsvValidationException Increments the number of records read if the result passed in is not null.
| |
| verifyReader | back to summary |
|---|---|
| public boolean verifyReader() Returns if the CSVReader will verify the reader before each read. By default the value is true, which is the functionality for version 3.0. If set to false the reader is always assumed ready to read - this is the functionality for version 2.4 and before. The reason this method was needed was that certain types of readers would return false for their ready() methods until a read was done (namely readers created using Channels). This caused opencsv not to read from those readers.
| |