java.lang.Object
de.siegmar.fastcsv.writer.CsvWriter.CsvWriterBuilder
- Enclosing class:
CsvWriter
This builder is used to create configured instances of
CsvWriter. The default
configuration of this class complies with RFC 4180.
- field separator:
,(comma) - quote character:
"(double quote) - comment character:
#(hash/number) - quote strategy:
null(only required quoting) - line delimiter:
LineDelimiter.CRLF - buffer size: 8,192 bytes
-
Method Summary
Modifier and TypeMethodDescriptionbufferSize(int bufferSize) Configures the size of the internal buffer.Constructs aCsvWriterfor the specified Writer.build(Path file, Charset charset, OpenOption... openOptions) Constructs aCsvWriterfor the specified Path.build(Path file, OpenOption... openOptions) Constructs aCsvWriterfor the specified Path.commentCharacter(char commentCharacter) Sets the character that is used to prepend commented lines – default:#(hash/number).fieldSeparator(char fieldSeparator) Sets the character that is used to separate fields – default:,(comma).lineDelimiter(LineDelimiter lineDelimiter) Sets the delimiter that is used to separate lines (default:LineDelimiter.CRLF).quoteCharacter(char quoteCharacter) Sets the character that is used to quote values – default:"(double quote).quoteStrategy(QuoteStrategy quoteStrategy) Sets the strategy that defines when optional quoting has to be performed – default: none.toString()
-
Method Details
-
fieldSeparator
Sets the character that is used to separate fields – default:,(comma).- Parameters:
fieldSeparator- the field separator character.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
quoteCharacter
Sets the character that is used to quote values – default:"(double quote).Be aware that using characters other than the default double quote character goes against the RFC 4180 standard.
- Parameters:
quoteCharacter- the character for enclosing fields.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
commentCharacter
Sets the character that is used to prepend commented lines – default:#(hash/number).- Parameters:
commentCharacter- the character for prepending commented lines.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
quoteStrategy
Sets the strategy that defines when optional quoting has to be performed – default: none.- Parameters:
quoteStrategy- the strategy when fields should be enclosed using thequoteCharacter, even if not strictly required.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
lineDelimiter
Sets the delimiter that is used to separate lines (default:LineDelimiter.CRLF).- Parameters:
lineDelimiter- the line delimiter to be used.- Returns:
- This updated object, allowing additional method calls to be chained together.
-
bufferSize
Configures the size of the internal buffer.The default buffer size of 8,192 bytes usually does not need to be altered. One use-case is if you need many instances of a CsvWriter and need to optimize for instantiation time and memory footprint.
A buffer size of 0 disables the buffer.
- Parameters:
bufferSize- the buffer size to be used (must be ≥ 0).- Returns:
- This updated object, allowing additional method calls to be chained together.
-
build
Constructs aCsvWriterfor the specified Writer.This library uses built-in buffering (unless
bufferSize(int)is used to disable it) but writes its internal buffer to the givenwriterat the end of every record write operation. Therefore, you probably want to pass in aBufferedWriterto retain good performance. Usebuild(Path, Charset, OpenOption...)for optimal performance when writing files!- Parameters:
writer- the Writer to use for writing CSV data.- Returns:
- a new CsvWriter instance - never
null. - Throws:
NullPointerException- if writer isnull
-
build
Constructs aCsvWriterfor the specified Path.- Parameters:
file- the file to write data to.openOptions- options specifying how the file is opened. SeeFiles.newOutputStream(Path, OpenOption...)for defaults.- Returns:
- a new CsvWriter instance - never
null. Don't forget to close it! - Throws:
IOException- if a write error occursNullPointerException- if file or charset isnull
-
build
Constructs aCsvWriterfor the specified Path.- Parameters:
file- the file to write data to.charset- the character set to be used for writing data to the file.openOptions- options specifying how the file is opened. SeeFiles.newOutputStream(Path, OpenOption...)for defaults.- Returns:
- a new CsvWriter instance - never
null. Don't forget to close it! - Throws:
IOException- if a write error occursNullPointerException- if file or charset isnull
-
toString
-