Package com.opencsv
Class CSVReaderBuilder
Builder for creating a
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();
- See Also:
-
Field Summary
Fields inherited from class com.opencsv.CSVReaderBaseBuilder
errorLocale, icsvParser, keepCR, lineValidatorAggregator, multilineLimit, nullFieldIndicator, reader, rowProcessor, rowValidatorAggregator, skipLines, verifyReader -
Constructor Summary
ConstructorsConstructorDescriptionCSVReaderBuilder(Reader reader) Sets the reader to an underlying CSV source. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates theCSVReader.withCSVParser(ICSVParser icsvParser) Sets the parser to use to parse the input.withErrorLocale(Locale errorLocale) Sets the locale for all error messages.withFieldAsNull(CSVReaderNullFieldIndicator indicator) Checks to see if it should treat a field with two separators, two quotes, or both as a null field.withKeepCarriageReturn(boolean keepCR) Sets if the reader will keep or discard carriage returns.withLineValidator(LineValidator lineValidator) Adds aLineValidatorto theCSVReader.withMultilineLimit(int multilineLimit) Sets the maximum number of lines allowed in a multiline record.withRowProcessor(RowProcessor rowProcessor) Adds aRowProcessorto theCSVReader.withRowValidator(RowValidator rowValidator) Adds aRowValidatorto theCSVReader.withSkipLines(int skipLines) Sets the number of lines to skip before reading.withVerifyReader(boolean verifyReader) Checks to see if theCSVReadershould verify the reader state before reads or not.Methods inherited from class com.opencsv.CSVReaderBaseBuilder
getCsvParser, getErrorLocale, getLineValidatorAggregator, getMultilineLimit, getOrCreateCsvParser, getReader, getRowValidatorAggregator, getSkipLines, isVerifyReader, keepCarriageReturn
-
Constructor Details
-
CSVReaderBuilder
Sets the reader to an underlying CSV source.- Parameters:
reader- The reader to an underlying CSV source.
-
-
Method Details
-
withSkipLines
Sets the number of lines to skip before reading.- Parameters:
skipLines- The number of lines to skip before reading.- Returns:
this
-
withCSVParser
Sets the parser to use to parse the input.- Parameters:
icsvParser- The parser to use to parse the input.- Returns:
this
-
build
Creates theCSVReader.- Specified by:
buildin classCSVReaderBaseBuilder<CSVReader>- Returns:
- The
CSVReaderbased on the set criteria.
-
withKeepCarriageReturn
Sets if the reader will keep or discard carriage returns.- Parameters:
keepCR- True to keep carriage returns, false to discard.- Returns:
this
-
withVerifyReader
Checks to see if theCSVReadershould 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.
- Parameters:
verifyReader- True ifCSVReadershould verify reader before each read, false otherwise.- Returns:
this
-
withFieldAsNull
Checks to see if it should treat a field with two separators, two quotes, or both as a null field.- Parameters:
indicator-CSVReaderNullFieldIndicatorset to what should be considered a null field.- Returns:
this
-
withMultilineLimit
Sets the maximum number of lines allowed in a multiline record. More than this number in one record results in an IOException.- Parameters:
multilineLimit- No more than this number of lines is allowed in a single input record. The default isCSVReader.DEFAULT_MULTILINE_LIMIT.- Returns:
this
-
withErrorLocale
Sets the locale for all error messages.- Parameters:
errorLocale- Locale for error messages- Returns:
this- Since:
- 4.0
-
withLineValidator
- Parameters:
lineValidator-LineValidatorto inject.- Returns:
this- Since:
- 5.0
-
withRowValidator
- Parameters:
rowValidator-RowValidatorto inject- Returns:
this- Since:
- 5.0
-
withRowProcessor
Adds aRowProcessorto theCSVReader. Only a singleRowProcessorcan be added so multiple calls will overwrite the previously setRowProcessor.- Parameters:
rowProcessor-RowProcessorto inject- Returns:
this- Since:
- 5.0
-