public class CSVReaderBuilder extends CSVReaderBaseBuilder<CSVReader>
CSVReader.
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();
CSVReadererrorLocale, icsvParser, keepCR, lineValidatorAggregator, multilineLimit, nullFieldIndicator, reader, rowProcessor, rowValidatorAggregator, skipLines, verifyReader| 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. |
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. |
getCsvParser, getErrorLocale, getLineValidatorAggregator, getMultilineLimit, getOrCreateCsvParser, getReader, getRowValidatorAggregator, getSkipLines, isVerifyReader, keepCarriageReturnpublic CSVReaderBuilder(Reader reader)
reader - The reader to an underlying CSV source.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()
CSVReader.build in class CSVReaderBaseBuilder<CSVReader>CSVReader based on the set criteria.public CSVReaderBuilder withKeepCarriageReturn(boolean keepCR)
keepCR - True to keep carriage returns, false to discard.thispublic CSVReaderBuilder withVerifyReader(boolean verifyReader)
CSVReader should verify the reader state before
reads or not.
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 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 CSVReaderBuilder withLineValidator(LineValidator lineValidator)
lineValidator - LineValidator to inject.thispublic CSVReaderBuilder withRowValidator(RowValidator rowValidator)
rowValidator - RowValidator to injectthispublic CSVReaderBuilder withRowProcessor(RowProcessor rowProcessor)
RowProcessor to the CSVReader.
Only a single RowProcessor can be added so multiple calls will overwrite
the previously set RowProcessor.rowProcessor - RowProcessor to injectthisCopyright © 2005–2025. All rights reserved.