public class CSVReaderBuilder extends Object
This should be the preferred method of creating a Reader as there are so many
possible values to be set it is impossible to have constructors for all of
them and keep backwards compatibility with previous constructors.
final CSVParser parser =
new CSVParserBuilder()
.withSeparator('\t')
.withIgnoreQuotations(true)
.build();
final CSVReader reader =
new CSVReaderBuilder(new StringReader(csv))
.withSkipLines(1)
.withCSVParser(parser)
.build();
CSVReader
Constructor and Description |
---|
CSVReaderBuilder(Reader reader)
Sets the reader to an underlying CSV source.
|
Modifier and Type | Method and Description |
---|---|
CSVReader |
build()
Creates the CSVReader.
|
protected ICSVParser |
getCsvParser()
Used by unit tests.
|
protected int |
getMultilineLimit()
Used by unit tests.
|
protected Reader |
getReader()
Used by unit tests.
|
protected int |
getSkipLines()
Used by unit tests.
|
protected boolean |
keepCarriageReturn()
Returns if the reader built will keep or discard carriage returns.
|
CSVReaderBuilder |
withCSVParser(ICSVParser icsvParser)
Sets the parser to use to parse the input.
|
CSVReaderBuilder |
withFieldAsNull(CSVReaderNullFieldIndicator indicator)
Checks to see if it should treat a field with two separators, two quotes, or both as a null field.
|
CSVReaderBuilder |
withKeepCarriageReturn(boolean keepCR)
Sets if the reader will keep or discard carriage returns.
|
CSVReaderBuilder |
withMultilineLimit(int multilineLimit)
Sets the maximum number of lines allowed in a multiline record.
|
CSVReaderBuilder |
withSkipLines(int skipLines)
Sets the number of lines to skip before reading.
|
CSVReaderBuilder |
withVerifyReader(boolean verifyReader)
Checks to see if the CSVReader should verify the reader state before
reads or not.
|
public CSVReaderBuilder(Reader reader)
reader
- The reader to an underlying CSV source.protected Reader getReader()
protected int getSkipLines()
protected ICSVParser getCsvParser()
protected int getMultilineLimit()
public CSVReaderBuilder withSkipLines(int skipLines)
skipLines
- The number of lines to skip before reading.public CSVReaderBuilder withCSVParser(ICSVParser icsvParser)
icsvParser
- The parser to use to parse the input.public CSVReader build()
public CSVReaderBuilder withKeepCarriageReturn(boolean keepCR)
keepCR
- True to keep carriage returns, false to discard.protected boolean keepCarriageReturn()
public CSVReaderBuilder withVerifyReader(boolean verifyReader)
This should be set to false if you are using some form of asynchronous reader (like readers created by the java.nio.* classes).
The default value is true.
verifyReader
- True if CSVReader should verify reader before each read, false otherwise.public CSVReaderBuilder withFieldAsNull(CSVReaderNullFieldIndicator indicator)
indicator
- CSVReaderNullFieldIndicator set to what should be considered a null field.public CSVReaderBuilder withMultilineLimit(int multilineLimit)
multilineLimit
- No more than this number of lines is allowed in a
single input record. The default is CSVReader.DEFAULT_MULTILINE_LIMIT
.CSVReader.setMultilineLimit(int)
Copyright © 2017. All rights reserved.