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();
CSVReader
errorLocale, 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, keepCarriageReturn
public 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.this
public CSVReaderBuilder withCSVParser(ICSVParser icsvParser)
icsvParser
- The parser to use to parse the input.this
public 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.this
public 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.this
public CSVReaderBuilder withFieldAsNull(CSVReaderNullFieldIndicator indicator)
indicator
- CSVReaderNullFieldIndicator
set to what should be considered a null field.this
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
.this
public CSVReaderBuilder withErrorLocale(Locale errorLocale)
errorLocale
- Locale for error messagesthis
public CSVReaderBuilder withLineValidator(LineValidator lineValidator)
lineValidator
- LineValidator
to inject.this
public CSVReaderBuilder withRowValidator(RowValidator rowValidator)
rowValidator
- RowValidator
to injectthis
public 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 injectthis
Copyright © 2005–2023. All rights reserved.