Package org.beanio.stream.csv
Class CsvWriter
- java.lang.Object
-
- org.beanio.stream.csv.CsvWriter
-
- All Implemented Interfaces:
RecordWriter
public class CsvWriter extends java.lang.Object implements RecordWriter
ACsvWriter
is used to format and write records, ofString
arrays, to a CSV output stream. Using default settings, the CSV format supported is defined by specification RFC 4180.The writer also supports the following customizations:
- The default field delimiter, ',', may be overridden.
- The default quotation mark, '"', may be overridden.
- The default escape character, '"', may be overridden.
- The writer can be configured to qutoe every field. Otherwise a field is only quoted if it contains a quotation mark, delimiter, line feed or carriage return.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description CsvWriter(java.io.Writer out)
Constructs a newCsvWriter
using default settings.CsvWriter(java.io.Writer out, CsvParserConfiguration config)
Constructs a newCsvWriter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the output stream.void
flush()
Flushes the output stream.int
getLineNumber()
Returns the last line number written to the output stream.void
write(java.lang.Object value)
Writes a record object to this output stream.void
write(java.lang.String[] record)
Formats and writes a record to this output stream.
-
-
-
Constructor Detail
-
CsvWriter
public CsvWriter(java.io.Writer out)
Constructs a newCsvWriter
using default settings. according the RFC 4180 specification.- Parameters:
out
- the output stream to write to
-
CsvWriter
public CsvWriter(java.io.Writer out, CsvParserConfiguration config)
Constructs a newCsvWriter
.- Parameters:
out
- the output stream to write toconfig
- theCsvParserConfiguration
-
-
Method Detail
-
getLineNumber
public int getLineNumber()
Returns the last line number written to the output stream.- Returns:
- the last line number
-
write
public void write(java.lang.Object value) throws java.io.IOException
Description copied from interface:RecordWriter
Writes a record object to this output stream.- Specified by:
write
in interfaceRecordWriter
- Parameters:
value
- the record object to write- Throws:
java.io.IOException
- if an I/O error occurs writing the record to the stream
-
write
public void write(java.lang.String[] record) throws java.io.IOException
Formats and writes a record to this output stream.- Parameters:
record
- the record to write- Throws:
java.io.IOException
- if an I/O error occurs
-
flush
public void flush() throws java.io.IOException
Description copied from interface:RecordWriter
Flushes the output stream.- Specified by:
flush
in interfaceRecordWriter
- Throws:
java.io.IOException
- if an I/O error occurs flushing the stream
-
close
public void close() throws java.io.IOException
Description copied from interface:RecordWriter
Closes the output stream.- Specified by:
close
in interfaceRecordWriter
- Throws:
java.io.IOException
- if an I/O error occurs closing the stream
-
-