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
ACsvWriteris used to format and write records, ofStringarrays, 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 newCsvWriterusing 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 voidclose()Closes the output stream.voidflush()Flushes the output stream.intgetLineNumber()Returns the last line number written to the output stream.voidwrite(java.lang.Object value)Writes a record object to this output stream.voidwrite(java.lang.String[] record)Formats and writes a record to this output stream.
-
-
-
Constructor Detail
-
CsvWriter
public CsvWriter(java.io.Writer out)
Constructs a newCsvWriterusing 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.IOExceptionDescription copied from interface:RecordWriterWrites a record object to this output stream.- Specified by:
writein 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.IOExceptionFormats 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.IOExceptionDescription copied from interface:RecordWriterFlushes the output stream.- Specified by:
flushin interfaceRecordWriter- Throws:
java.io.IOException- if an I/O error occurs flushing the stream
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:RecordWriterCloses the output stream.- Specified by:
closein interfaceRecordWriter- Throws:
java.io.IOException- if an I/O error occurs closing the stream
-
-