Top Description Fields Constructors Methods
com.opencsv

public Class CSVReaderBuilder

extends CSVReaderBaseBuilder<CSVReader>
Class Inheritance
Imports
com.opencsv.enums.CSVReaderNullFieldIndicator, com.opencsv.processor.RowProcessor, com.opencsv.validators.LineValidator, .RowValidator, org.apache.commons.lang3.ObjectUtils, java.io.Reader, java.util.Locale, .ResourceBundle

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
com.opencsv.CSVReader

Field Summary

Inherited from com.opencsv.CSVReaderBaseBuilder:
errorLocaleicsvParserkeepCRlineValidatorAggregatormultilineLimitnullFieldIndicatorreaderrowProcessorrowValidatorAggregatorskipLinesverifyReader

Constructor Summary

AccessConstructor and Description
public
CSVReaderBuilder(final Reader
The reader to an underlying CSV source.
reader
)

Sets the reader to an underlying CSV source.

Method Summary

Modifier and TypeMethod and Description
public CSVReader

Returns:

The CSVReader based on the set criteria.
build
()

Implements abstract com.opencsv.CSVReaderBaseBuilder.build.

Creates the CSVReader.

public CSVReaderBuilder

Returns:

this
withCSVParser
(final ICSVParser
The parser to use to parse the input.
icsvParser
)

Sets the parser to use to parse the input.

public CSVReaderBuilder

Returns:

this
withErrorLocale
(Locale
Locale for error messages
errorLocale
)

Sets the locale for all error messages.

public CSVReaderBuilder

Returns:

this
withFieldAsNull
(CSVReaderNullFieldIndicator
CSVReaderNullFieldIndicator set to what should be considered a null field.
indicator
)

Checks to see if it should treat a field with two separators, two quotes, or both as a null field.

public CSVReaderBuilder

Returns:

this
withKeepCarriageReturn
(boolean
True to keep carriage returns, false to discard.
keepCR
)

Sets if the reader will keep or discard carriage returns.

public CSVReaderBuilder

Returns:

this
withLineValidator
(LineValidator
LineValidator to inject.
lineValidator
)

Adds a LineValidator to the CSVReader.

public CSVReaderBuilder

Returns:

this
withMultilineLimit
(int
No more than this number of lines is allowed in a single input record. The default is CSVReader#DEFAULT_MULTILINE_LIMIT.
multilineLimit
)

Sets the maximum number of lines allowed in a multiline record.

public CSVReaderBuilder

Returns:

this
withRowProcessor
(RowProcessor
RowProcessor to inject
rowProcessor
)

Adds a RowProcessor to the CSVReader.

public CSVReaderBuilder

Returns:

this
withRowValidator
(RowValidator
RowValidator to inject
rowValidator
)

Adds a RowValidator to the CSVReader.

public CSVReaderBuilder

Returns:

this
withSkipLines
(final int
The number of lines to skip before reading.
skipLines
)

Sets the number of lines to skip before reading.

public CSVReaderBuilder

Returns:

this
withVerifyReader
(boolean
True if CSVReader should verify reader before each read, false otherwise.
verifyReader
)

Checks to see if the CSVReader should verify the reader state before reads or not.

Inherited from com.opencsv.CSVReaderBaseBuilder:
getCsvParsergetErrorLocalegetLineValidatorAggregatorgetMultilineLimitgetOrCreateCsvParsergetReadergetRowValidatorAggregatorgetSkipLinesisVerifyReaderkeepCarriageReturn

Constructor Detail

CSVReaderBuilderback to summary
public CSVReaderBuilder(final Reader reader)

Sets the reader to an underlying CSV source.

Parameters
reader:Reader

The reader to an underlying CSV source.

Method Detail

buildback to summary
public CSVReader build()

Implements abstract com.opencsv.CSVReaderBaseBuilder.build.

Creates the CSVReader.

Returns:CSVReader

The CSVReader based on the set criteria.

Annotations
@Override
withCSVParserback to summary
public CSVReaderBuilder withCSVParser(final ICSVParser icsvParser)

Sets the parser to use to parse the input.

Parameters
icsvParser:ICSVParser

The parser to use to parse the input.

Returns:CSVReaderBuilder

this

withErrorLocaleback to summary
public CSVReaderBuilder withErrorLocale(Locale errorLocale)

Sets the locale for all error messages.

Parameters
errorLocale:Locale

Locale for error messages

Returns:CSVReaderBuilder

this

Since
4.0
withFieldAsNullback to summary
public CSVReaderBuilder withFieldAsNull(CSVReaderNullFieldIndicator indicator)

Checks to see if it should treat a field with two separators, two quotes, or both as a null field.

Parameters
indicator:CSVReaderNullFieldIndicator

CSVReaderNullFieldIndicator set to what should be considered a null field.

Returns:CSVReaderBuilder

this

withKeepCarriageReturnback to summary
public CSVReaderBuilder withKeepCarriageReturn(boolean keepCR)

Sets if the reader will keep or discard carriage returns.

Parameters
keepCR:boolean

True to keep carriage returns, false to discard.

Returns:CSVReaderBuilder

this

withLineValidatorback to summary
public CSVReaderBuilder withLineValidator(LineValidator lineValidator)

Adds a LineValidator to the CSVReader. Multiple LineValidators can be added with multiple calls.

Parameters
lineValidator:LineValidator

LineValidator to inject.

Returns:CSVReaderBuilder

this

Since
5.0
withMultilineLimitback to summary
public CSVReaderBuilder withMultilineLimit(int multilineLimit)

Sets the maximum number of lines allowed in a multiline record. More than this number in one record results in an IOException.

Parameters
multilineLimit:int

No more than this number of lines is allowed in a single input record. The default is CSVReader#DEFAULT_MULTILINE_LIMIT.

Returns:CSVReaderBuilder

this

withRowProcessorback to summary
public CSVReaderBuilder withRowProcessor(RowProcessor rowProcessor)

Adds a RowProcessor to the CSVReader. Only a single RowProcessor can be added so multiple calls will overwrite the previously set RowProcessor.

Parameters
rowProcessor:RowProcessor

RowProcessor to inject

Returns:CSVReaderBuilder

this

Since
5.0
withRowValidatorback to summary
public CSVReaderBuilder withRowValidator(RowValidator rowValidator)

Adds a RowValidator to the CSVReader. Multiple RowValidators can be added with multiple calls.

Parameters
rowValidator:RowValidator

RowValidator to inject

Returns:CSVReaderBuilder

this

Since
5.0
withSkipLinesback to summary
public CSVReaderBuilder withSkipLines(final int skipLines)

Sets the number of lines to skip before reading.

Parameters
skipLines:int

The number of lines to skip before reading.

Returns:CSVReaderBuilder

this

withVerifyReaderback to summary
public CSVReaderBuilder withVerifyReader(boolean verifyReader)

Checks to see if the 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.

Parameters
verifyReader:boolean

True if CSVReader should verify reader before each read, false otherwise.

Returns:CSVReaderBuilder

this