Module de.siegmar.fastcsv
Package de.siegmar.fastcsv.reader
Class IndexedCsvReader.IndexedCsvReaderBuilder
java.lang.Object
de.siegmar.fastcsv.reader.IndexedCsvReader.IndexedCsvReaderBuilder
- Enclosing class:
IndexedCsvReader<T>
This builder is used to create configured instances of
IndexedCsvReader. The default
configuration of this class adheres with RFC 4180.
The line delimiter (line-feed, carriage-return or the combination of both) is detected automatically and thus not configurable.
-
Method Summary
Modifier and TypeMethodDescriptionacceptCharsAfterQuotes(boolean acceptCharsAfterQuotes) Specifies whether the presence of characters between a closing quote and a field separator or the end of a line should be treated as an error or not.<T> IndexedCsvReader<T> build(CsvCallbackHandler<T> callbackHandler, Path file) Constructs a newIndexedCsvReaderfor the specified callback handler and path using UTF-8 as the character set.<T> IndexedCsvReader<T> build(CsvCallbackHandler<T> callbackHandler, Path file, Charset charset) Constructs a newIndexedCsvReaderfor the specified arguments.commentCharacter(char commentCharacter) Sets thecommentCharacterused to comment lines.commentStrategy(CommentStrategy commentStrategy) Sets the strategy that defines how (and if) commented lines should be handled (default:CommentStrategy.NONEas comments are not defined in RFC 4180).fieldSeparator(char fieldSeparator) Sets thefieldSeparatorused when reading CSV data.Sets a prebuilt index that should be used for accessing the file.ofCsvRecord(Path file) Constructs a newIndexedCsvReaderofCsvRecordfor the specified path using UTF-8 as the character set.ofCsvRecord(Path file, Charset charset) Constructs a newIndexedCsvReaderofCsvRecordfor the specified arguments.pageSize(int pageSize) Sets thepageSizefor pages returned byIndexedCsvReader.readPage(int)(default: 100).quoteCharacter(char quoteCharacter) Sets thequoteCharacterused when reading CSV data.statusListener(StatusListener statusListener) Sets thestatusListenerto listen for indexer status updates.
-
Method Details
-
fieldSeparator
Sets thefieldSeparatorused when reading CSV data.- Parameters:
fieldSeparator- the field separator character (default:,- comma).- Returns:
- This updated object, allowing additional method calls to be chained together.
-
quoteCharacter
Sets thequoteCharacterused when reading CSV data.- Parameters:
quoteCharacter- the character used to enclose fields (default:"- double quotes).- Returns:
- This updated object, allowing additional method calls to be chained together.
-
commentStrategy
Sets the strategy that defines how (and if) commented lines should be handled (default:CommentStrategy.NONEas comments are not defined in RFC 4180).- Parameters:
commentStrategy- the strategy for handling comments.- Returns:
- This updated object, allowing additional method calls to be chained together.
- Throws:
IllegalArgumentException- ifCommentStrategy.SKIPis passed, as this is not supported- See Also:
-
commentCharacter
Sets thecommentCharacterused to comment lines.- Parameters:
commentCharacter- the character used to comment lines (default:#- hash)- Returns:
- This updated object, allowing additional method calls to be chained together.
- See Also:
-
acceptCharsAfterQuotes
public IndexedCsvReader.IndexedCsvReaderBuilder acceptCharsAfterQuotes(boolean acceptCharsAfterQuotes) Specifies whether the presence of characters between a closing quote and a field separator or the end of a line should be treated as an error or not.Example:
"a"b,"c"If this is set to
true, the valueabwill be returned for the first field.If this is set to
false, aCsvParseExceptionwill be thrown.- Parameters:
acceptCharsAfterQuotes- allow characters after quotes (default:true).- Returns:
- This updated object, allowing additional method calls to be chained together.
-
statusListener
Sets thestatusListenerto listen for indexer status updates.- Parameters:
statusListener- the status listener.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
index
Sets a prebuilt index that should be used for accessing the file.- Parameters:
csvIndex- a prebuilt index- Returns:
- This updated object, allowing additional method calls to be chained together.
-
pageSize
Sets thepageSizefor pages returned byIndexedCsvReader.readPage(int)(default: 100).- Parameters:
pageSize- the maximum size of pages.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
ofCsvRecord
Constructs a newIndexedCsvReaderofCsvRecordfor the specified path using UTF-8 as the character set.Convenience method for
build(CsvCallbackHandler, Path, Charset)withCsvRecordHandleras the callback handler andStandardCharsets.UTF_8as the charset.- Parameters:
file- the file to read data from.- Returns:
- a new IndexedCsvReader - never
null. Remember to close it! - Throws:
IOException- if an I/O error occurs.NullPointerException- if file or charset isnull
-
ofCsvRecord
Constructs a newIndexedCsvReaderofCsvRecordfor the specified arguments.Convenience method for
build(CsvCallbackHandler, Path, Charset)withCsvRecordHandleras the callback handler.- Parameters:
file- the file to read data from.charset- the character set to use.- Returns:
- a new IndexedCsvReader - never
null. Remember to close it! - Throws:
IOException- if an I/O error occurs.NullPointerException- if file or charset isnull
-
build
public <T> IndexedCsvReader<T> build(CsvCallbackHandler<T> callbackHandler, Path file) throws IOException Constructs a newIndexedCsvReaderfor the specified callback handler and path using UTF-8 as the character set.Convenience method for
build(CsvCallbackHandler, Path, Charset)withStandardCharsets.UTF_8as charset.- Type Parameters:
T- the type of the CSV record.- Parameters:
callbackHandler- the callback handler to use.file- the file to read data from.- Returns:
- a new IndexedCsvReader - never
null. Remember to close it! - Throws:
IOException- if an I/O error occurs.NullPointerException- if callbackHandler, file or charset isnull
-
build
public <T> IndexedCsvReader<T> build(CsvCallbackHandler<T> callbackHandler, Path file, Charset charset) throws IOException Constructs a newIndexedCsvReaderfor the specified arguments.- Type Parameters:
T- the type of the CSV record.- Parameters:
callbackHandler- the callback handler to use.file- the file to read data from.charset- the character set to use.- Returns:
- a new IndexedCsvReader - never
null. Remember to close it! - Throws:
IOException- if an I/O error occurs.NullPointerException- if callbackHandler, file or charset isnull
-