Example use:
try (CsvWriter csv = CsvWriter.builder().build(file)) {
csv.writeRecord("Hello", "world");
}
| Modifier and Type | Class and Description |
|---|---|
| public static class | CsvWriter.
This builder is used to create configured instances of |
| public class | CsvWriter.
This class is used to write a record field by field. |
| Modifier and Type | Field and Description |
|---|---|
| private final char | |
| private int | |
| private final char[] | |
| private final char | |
| private final LineDelimiter | |
| private final char[] | |
| private boolean | |
| private final char | |
| private final QuoteStrategy | |
| private final Writable |
| Access | Constructor and Description |
|---|---|
| pack-priv | CsvWriter(final Writable writer, final char fieldSeparator, final char quoteCharacter, final char commentCharacter, final QuoteStrategy quoteStrategy, final LineDelimiter lineDelimiter)
|
| Modifier and Type | Method and Description |
|---|---|
| public static CsvWriter. | Returns: CsvWriterBuilder instance with default settings.Creates a |
| public void | close()
Implements java. Closes this stream and releases any system resources associated with it. |
| private boolean | |
| private CsvWriter | |
| public void | flush()
Implements java. Flushes this stream by writing any buffered output to the underlying stream. |
| public String | |
| private void | |
| public CsvWriter | Returns: This CsvWriter.the comment to write. The comment character
(configured by comment)CsvWriterBuilder#commentCharacter(char)) is automatically prepended.
Empty or null values results in a line only consisting of the comment character.
If the argument comment contains line break characters (CR, LF), multiple comment lines
will be written, terminated with the line break character configured by
CsvWriterBuilder#lineDelimiter(LineDelimiter).Writes a comment line and new line character(s) at the end. |
| private void | |
| private static void | |
| private void | |
| private void | |
| public CsvWriter | Returns: This CsvWriter.the fields to write ( values)null values are handled as empty strings, if
not configured otherwise (QuoteStrategies#EMPTY)).Writes a complete line - one or more fields and new line character(s) at the end. |
| public CsvWriter | Returns: This CsvWriter.the fields to write ( values)null values are handled as empty strings, if
not configured otherwise (QuoteStrategies#EMPTY))Writes a complete line - one or more fields and new line character(s) at the end. |
| public CsvWriter. |
| commentCharacter | back to summary |
|---|---|
| private final char commentCharacter | |
| currentLineNo | back to summary |
|---|---|
| private int currentLineNo | |
| emptyFieldValue | back to summary |
|---|---|
| private final char[] emptyFieldValue | |
| fieldSeparator | back to summary |
|---|---|
| private final char fieldSeparator | |
| lineDelimiter | back to summary |
|---|---|
| private final LineDelimiter lineDelimiter | |
| lineDelimiterChars | back to summary |
|---|---|
| private final char[] lineDelimiterChars | |
| openRecordWriter | back to summary |
|---|---|
| private boolean openRecordWriter | |
| quoteCharacter | back to summary |
|---|---|
| private final char quoteCharacter | |
| quoteStrategy | back to summary |
|---|---|
| private final QuoteStrategy quoteStrategy | |
| writer | back to summary |
|---|---|
| private final Writable writer | |
| CsvWriter | back to summary |
|---|---|
pack-priv CsvWriter(final Writable writer, final char fieldSeparator, final char quoteCharacter, final char commentCharacter, final QuoteStrategy quoteStrategy, final LineDelimiter lineDelimiter)
| |
| builder | back to summary |
|---|---|
| public static CsvWriter. Creates a
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in
| |
| containsControlCharacter | back to summary |
|---|---|
private boolean containsControlCharacter(final String value, final int fieldIdx, final int length)
| |
| endRecord | back to summary |
|---|---|
| private CsvWriter endRecord() throws IOException | |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Implements java. Doc from java. Flushes this stream by writing any buffered output to the underlying stream.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| validateNoOpenRecord | back to summary |
|---|---|
| private void validateNoOpenRecord() | |
| writeComment | back to summary |
|---|---|
| public CsvWriter writeComment(final String comment) Writes a comment line and new line character(s) at the end. Note that comments are not part of the CSV standard and may not be supported by all readers.
| |
| writeCommentInternal | back to summary |
|---|---|
| private void writeCommentInternal(final String comment) throws IOException | |
| writeEscaped | back to summary |
|---|---|
| private static void writeEscaped(final Writable w, final String value, final char quoteChar) throws IOException | |
| writeFragment | back to summary |
|---|---|
| private void writeFragment(final String comment, final int i, final int startPos) throws IOException | |
| writeInternal | back to summary |
|---|---|
private void writeInternal(final String value, final int fieldIdx) throws IOException
| |
| writeRecord | back to summary |
|---|---|
| public CsvWriter writeRecord(final Iterable<String> values) Writes a complete line - one or more fields and new line character(s) at the end.
| |
| writeRecord | back to summary |
|---|---|
| public CsvWriter writeRecord(final String... values) Writes a complete line - one or more fields and new line character(s) at the end.
| |
| writeRecord | back to summary |
|---|---|
| public CsvWriter. Starts a new record. This method is used to write a record field by field. The record is ended by calling
| |
CsvWriter. The default
configuration of this class adheres with RFC 4180.
, (comma)
" (double quote)
# (hash/number)
QuoteStrategies#REQUIRED
LineDelimiter#CRLF
false
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private int | |
| private char | |
| private static final int | |
| private char | |
| private LineDelimiter | |
| private char | |
| private QuoteStrategy |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.whether the data should be flushed after each record write operation. autoFlush)Configures whether data should be flushed after each record write operation. |
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.the buffer size to be used (must be ≥ 0). bufferSize)Configures the size of the internal buffer. |
| public CsvWriter | Returns: a new CsvWriter instance - nevernull. Remember to close it!the OutputStream to write CSV data to. outputStream)Constructs a |
| public CsvWriter | Returns: a new CsvWriter instance - nevernull. Remember to close it!the OutputStream to write CSV data to. outputStream, final Charset the character set to be used for writing data to the output stream. charset)Constructs a |
| public CsvWriter | |
| public CsvWriter | Returns: a new CsvWriter instance - nevernull. Remember to close it!the file to write data to. file, final OpenOption... options specifying how the file is opened.
See openOptions)Files#newOutputStream(Path, OpenOption. for defaults.Constructs a |
| public CsvWriter | Returns: a new CsvWriter instance - nevernull. Remember to close it!the file to write data to. file, final Charset the character set to be used for writing data to the file. charset, final OpenOption... options specifying how the file is opened.
See openOptions)Files#newOutputStream(Path, OpenOption. for defaults.Constructs a |
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.the character for prepending commented lines. commentCharacter)Sets the character used to prepend commented lines – default: |
| private CsvWriter | |
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.the field separator character. fieldSeparator)Sets the character that is used to separate fields – default: |
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.the line delimiter to be used; must not be lineDelimiter)null.Sets the delimiter used to separate lines (default: |
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.the character for enclosing fields. quoteCharacter)Sets the character used to quote values – default: |
| public CsvWriter. | Returns: This updated object, allowing additional method calls to be chained together.the strategy when fields should be enclosed using the quoteStrategy)quoteCharacter,
even if not strictly required; must not be null.Sets the strategy that defines when optional quoting has to be performed
(default: |
| public CsvWriter | Returns: a new CsvWriter instance - nevernull.
Calls to CsvWriter#close() are ignored, standard out remains open.Convenience method to write to the console (standard output). |
| public String | |
| private static Writable |
| autoFlush | back to summary |
|---|---|
| private boolean autoFlush | |
| bufferSize | back to summary |
|---|---|
| private int bufferSize | |
| commentCharacter | back to summary |
|---|---|
| private char commentCharacter | |
| DEFAULT_BUFFER_SIZE | back to summary |
|---|---|
| private static final int DEFAULT_BUFFER_SIZE | |
| fieldSeparator | back to summary |
|---|---|
| private char fieldSeparator | |
| lineDelimiter | back to summary |
|---|---|
| private LineDelimiter lineDelimiter | |
| quoteCharacter | back to summary |
|---|---|
| private char quoteCharacter | |
| quoteStrategy | back to summary |
|---|---|
| private QuoteStrategy quoteStrategy | |
| CsvWriterBuilder | back to summary |
|---|---|
| pack-priv CsvWriterBuilder() | |
| autoFlush | back to summary |
|---|---|
| public CsvWriter. Configures whether data should be flushed after each record write operation. Obviously this comes with drastic performance implications but can be useful for debugging purposes. This setting is ignored when using
| |
| bufferSize | back to summary |
|---|---|
| public CsvWriter. 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. This setting is ignored when using
| |
| build | back to summary |
|---|---|
| public CsvWriter build(final OutputStream outputStream) Constructs a See
| |
| build | back to summary |
|---|---|
| public CsvWriter build(final OutputStream outputStream, final Charset charset) Constructs a This build method wraps the given Use
| |
| build | back to summary |
|---|---|
| public CsvWriter build(final Writer writer) Constructs a This library uses built-in buffering, unless Use
| |
| build | back to summary |
|---|---|
| public CsvWriter build(final Path file, final OpenOption... openOptions) throws IOException Constructs a See
| |
| build | back to summary |
|---|---|
| public CsvWriter build(final Path file, final Charset charset, final OpenOption... openOptions) throws IOException Constructs a
| |
| commentCharacter | back to summary |
|---|---|
| public CsvWriter. Sets the character used to prepend commented lines – default:
| |
| csvWriter | back to summary |
|---|---|
| private CsvWriter csvWriter(final Writer writer, final int bufferSize, final boolean autoFlushWriter) | |
| fieldSeparator | back to summary |
|---|---|
| public CsvWriter. Sets the character that is used to separate fields – default:
| |
| lineDelimiter | back to summary |
|---|---|
| public CsvWriter. Sets the delimiter used to separate lines (default:
| |
| quoteCharacter | back to summary |
|---|---|
| public CsvWriter. Sets the character used to quote values – default: Be aware that using characters other than the default double quote character goes against the RFC 4180 standard.
| |
| quoteStrategy | back to summary |
|---|---|
| public CsvWriter. Sets the strategy that defines when optional quoting has to be performed
(default:
| |
| toConsole | back to summary |
|---|---|
| public CsvWriter toConsole() Convenience method to write to the console (standard output). Settings Example use: CsvWriter.builder().toConsole()
.writeRecord("Hello", "world");
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| wrapWriter | back to summary |
|---|---|
| private static Writable wrapWriter(final Writer writer, final int bufferSize, final boolean autoFlushWriter) | |
The record is ended by calling endRecord().
| Modifier and Type | Field and Description |
|---|---|
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public CsvWriter | |
| public CsvWriter. | Returns: this CsvWriterRecord instancethe field value value)Writes a field to the current record. |
| fieldIdx | back to summary |
|---|---|
| private int fieldIdx | |
| CsvWriterRecord | back to summary |
|---|---|
| private CsvWriterRecord() | |
| endRecord | back to summary |
|---|---|
| public CsvWriter endRecord() Ends the current record.
| |
| writeField | back to summary |
|---|---|
| public CsvWriter. Writes a field to the current record.
| |