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>
public static final class IndexedCsvReader.IndexedCsvReaderBuilder extends java.lang.Object
This builder is used to create configured instances ofIndexedCsvReader
. 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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
acceptCharsAfterQuotes
private char
commentCharacter
private CommentStrategy
commentStrategy
private CsvIndex
csvIndex
private static int
DEFAULT_PAGE_SIZE
private char
fieldSeparator
private static int
MAX_BASE_ASCII
private static int
MIN_PAGE_SIZE
private int
pageSize
private char
quoteCharacter
private StatusListener
statusListener
-
Constructor Summary
Constructors Modifier Constructor Description private
IndexedCsvReaderBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.<T> IndexedCsvReader<T>
build(CsvCallbackHandler<T> callbackHandler, java.nio.file.Path file)
Constructs a newIndexedCsvReader
for the specified callback handler and path using UTF-8 as the character set.<T> IndexedCsvReader<T>
build(CsvCallbackHandler<T> callbackHandler, java.nio.file.Path file, java.nio.charset.Charset charset)
Constructs a newIndexedCsvReader
for the specified arguments.private static void
checkControlCharacter(char controlChar)
IndexedCsvReader.IndexedCsvReaderBuilder
commentCharacter(char commentCharacter)
Sets thecommentCharacter
used to comment lines.IndexedCsvReader.IndexedCsvReaderBuilder
commentStrategy(CommentStrategy commentStrategy)
Sets the strategy that defines how (and if) commented lines should be handled (default:CommentStrategy.NONE
as comments are not defined in RFC 4180).IndexedCsvReader.IndexedCsvReaderBuilder
fieldSeparator(char fieldSeparator)
Sets thefieldSeparator
used when reading CSV data.IndexedCsvReader.IndexedCsvReaderBuilder
index(CsvIndex csvIndex)
Sets a prebuilt index that should be used for accessing the file.IndexedCsvReader<CsvRecord>
ofCsvRecord(java.nio.file.Path file)
Constructs a newIndexedCsvReader
ofCsvRecord
for the specified path using UTF-8 as the character set.IndexedCsvReader<CsvRecord>
ofCsvRecord(java.nio.file.Path file, java.nio.charset.Charset charset)
Constructs a newIndexedCsvReader
ofCsvRecord
for the specified arguments.IndexedCsvReader.IndexedCsvReaderBuilder
pageSize(int pageSize)
IndexedCsvReader.IndexedCsvReaderBuilder
quoteCharacter(char quoteCharacter)
Sets thequoteCharacter
used when reading CSV data.IndexedCsvReader.IndexedCsvReaderBuilder
statusListener(StatusListener statusListener)
Sets thestatusListener
to listen for indexer status updates.
-
-
-
Field Detail
-
MAX_BASE_ASCII
private static final int MAX_BASE_ASCII
- See Also:
- Constant Field Values
-
DEFAULT_PAGE_SIZE
private static final int DEFAULT_PAGE_SIZE
- See Also:
- Constant Field Values
-
MIN_PAGE_SIZE
private static final int MIN_PAGE_SIZE
- See Also:
- Constant Field Values
-
fieldSeparator
private char fieldSeparator
-
quoteCharacter
private char quoteCharacter
-
commentStrategy
private CommentStrategy commentStrategy
-
commentCharacter
private char commentCharacter
-
acceptCharsAfterQuotes
private boolean acceptCharsAfterQuotes
-
statusListener
private StatusListener statusListener
-
pageSize
private int pageSize
-
csvIndex
private CsvIndex csvIndex
-
-
Method Detail
-
fieldSeparator
public IndexedCsvReader.IndexedCsvReaderBuilder fieldSeparator(char fieldSeparator)
Sets thefieldSeparator
used 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
public IndexedCsvReader.IndexedCsvReaderBuilder quoteCharacter(char quoteCharacter)
Sets thequoteCharacter
used 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
public IndexedCsvReader.IndexedCsvReaderBuilder commentStrategy(CommentStrategy commentStrategy)
Sets the strategy that defines how (and if) commented lines should be handled (default:CommentStrategy.NONE
as 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:
java.lang.IllegalArgumentException
- ifCommentStrategy.SKIP
is passed, as this is not supported- See Also:
commentCharacter(char)
-
commentCharacter
public IndexedCsvReader.IndexedCsvReaderBuilder commentCharacter(char commentCharacter)
Sets thecommentCharacter
used 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:
commentStrategy(CommentStrategy)
-
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 valueab
will be returned for the first field.If this is set to
false
, aCsvParseException
will be thrown.- Parameters:
acceptCharsAfterQuotes
- allow characters after quotes (default:true
).- Returns:
- This updated object, allowing additional method calls to be chained together.
-
statusListener
public IndexedCsvReader.IndexedCsvReaderBuilder statusListener(StatusListener statusListener)
Sets thestatusListener
to listen for indexer status updates.- Parameters:
statusListener
- the status listener.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
index
public IndexedCsvReader.IndexedCsvReaderBuilder index(CsvIndex csvIndex)
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
public IndexedCsvReader.IndexedCsvReaderBuilder pageSize(int pageSize)
- Parameters:
pageSize
- the maximum size of pages.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
checkControlCharacter
private static void checkControlCharacter(char controlChar)
-
ofCsvRecord
public IndexedCsvReader<CsvRecord> ofCsvRecord(java.nio.file.Path file) throws java.io.IOException
Constructs a newIndexedCsvReader
ofCsvRecord
for the specified path using UTF-8 as the character set.Convenience method for
build(CsvCallbackHandler, Path, Charset)
withCsvRecordHandler
as the callback handler andStandardCharsets.UTF_8
as the charset.- Parameters:
file
- the file to read data from.- Returns:
- a new IndexedCsvReader - never
null
. Remember to close it! - Throws:
java.io.IOException
- if an I/O error occurs.java.lang.NullPointerException
- if file or charset isnull
-
ofCsvRecord
public IndexedCsvReader<CsvRecord> ofCsvRecord(java.nio.file.Path file, java.nio.charset.Charset charset) throws java.io.IOException
Constructs a newIndexedCsvReader
ofCsvRecord
for the specified arguments.Convenience method for
build(CsvCallbackHandler, Path, Charset)
withCsvRecordHandler
as 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:
java.io.IOException
- if an I/O error occurs.java.lang.NullPointerException
- if file or charset isnull
-
build
public <T> IndexedCsvReader<T> build(CsvCallbackHandler<T> callbackHandler, java.nio.file.Path file) throws java.io.IOException
Constructs a newIndexedCsvReader
for the specified callback handler and path using UTF-8 as the character set.Convenience method for
build(CsvCallbackHandler, Path, Charset)
withStandardCharsets.UTF_8
as 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:
java.io.IOException
- if an I/O error occurs.java.lang.NullPointerException
- if callbackHandler, file or charset isnull
-
build
public <T> IndexedCsvReader<T> build(CsvCallbackHandler<T> callbackHandler, java.nio.file.Path file, java.nio.charset.Charset charset) throws java.io.IOException
Constructs a newIndexedCsvReader
for 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:
java.io.IOException
- if an I/O error occurs.java.lang.NullPointerException
- if callbackHandler, file or charset isnull
-
-