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.
|
Locale |
getErrorLocale() |
LineValidatorAggregator |
getLineValidatorAggregator() |
protected int |
getMultilineLimit()
Used by unit tests.
|
protected ICSVParser |
getOrCreateCsvParser()
Creates a new
ICSVParser if the class does't already hold one. |
protected Reader |
getReader()
Used by unit tests.
|
RowValidatorAggregator |
getRowValidatorAggregator() |
protected int |
getSkipLines()
Used by unit tests.
|
boolean |
isVerifyReader() |
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 |
withErrorLocale(Locale errorLocale)
Sets the locale for all error messages.
|
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 |
withLineValidator(LineValidator lineValidator)
Adds a LineValidator to the CSVReader.
|
CSVReaderBuilder |
withMultilineLimit(int multilineLimit)
Sets the maximum number of lines allowed in a multiline record.
|
CSVReaderBuilder |
withRowProcessor(RowProcessor rowProcessor)
Adds a RowProcessor to the CSVReader.
|
CSVReaderBuilder |
withRowValidator(RowValidator rowValidator)
Adds a RowValidator to the CSVReader.
|
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.thispublic CSVReaderBuilder withCSVParser(ICSVParser icsvParser)
icsvParser - The parser to use to parse the input.thispublic CSVReader build()
public CSVReaderBuilder withKeepCarriageReturn(boolean keepCR)
keepCR - True to keep carriage returns, false to discard.thisprotected boolean keepCarriageReturn()
true if the reader built will keep carriage returns,
false otherwiseprotected ICSVParser getOrCreateCsvParser()
ICSVParser if the class does't already hold one.ICSVParser or a default parser.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.thispublic boolean isVerifyReader()
public CSVReaderBuilder withFieldAsNull(CSVReaderNullFieldIndicator indicator)
indicator - CSVReaderNullFieldIndicator set to what should be considered a null field.thispublic 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.thispublic CSVReaderBuilder withErrorLocale(Locale errorLocale)
errorLocale - Locale for error messagesthispublic Locale getErrorLocale()
public LineValidatorAggregator getLineValidatorAggregator()
public RowValidatorAggregator getRowValidatorAggregator()
public CSVReaderBuilder withLineValidator(LineValidator lineValidator)
lineValidator - LineValidator to inject.thispublic CSVReaderBuilder withRowValidator(RowValidator rowValidator)
rowValidator - RowValidator to injectthispublic CSVReaderBuilder withRowProcessor(RowProcessor rowProcessor)
rowProcessor - RowProcessor to injectthisCopyright © 2019. All rights reserved.