BeanIO 1.2.3

org.beanio.stream.csv
Class CsvWriter

java.lang.Object
  extended by org.beanio.stream.csv.CsvWriter
All Implemented Interfaces:
RecordWriter

public class CsvWriter
extends Object
implements RecordWriter

A CsvWriter is used to format and write records, of String 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:

Since:
1.0
Author:
Kevin Seim

Constructor Summary
CsvWriter(Writer out)
          Constructs a new CsvWriter using default settings according the RFC 4180 specification.
CsvWriter(Writer out, boolean alwaysQuote, char escapeCharacter)
          Constructs a new CsvWriter.
CsvWriter(Writer out, char delimiter, char quote, boolean alwaysQuote, char escapeCharacter, String lineSeparator)
          Constructs a new CsvWriter.
 
Method Summary
 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(Object value)
          Writes a record object to this output stream.
 void write(String[] record)
          Formats and writes a record to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvWriter

public CsvWriter(Writer out)
Constructs a new CsvWriter using default settings according the RFC 4180 specification.

Parameters:
out - the output stream to write to

CsvWriter

public CsvWriter(Writer out,
                 boolean alwaysQuote,
                 char escapeCharacter)
Constructs a new CsvWriter.

Parameters:
out - the output stream to write to
alwaysQuote - set to true if all fields are always quoted, otherwise a field is only quoted if it contains a quotation mark, delimiter, new line or carriage return
escapeCharacter - the character used to escape quotation marks and itself in the output

CsvWriter

public CsvWriter(Writer out,
                 char delimiter,
                 char quote,
                 boolean alwaysQuote,
                 char escapeCharacter,
                 String lineSeparator)
Constructs a new CsvWriter.

Parameters:
out - the output stream to write to
delimiter - the field delimiter
quote - the quotation mark
alwaysQuote - set to true if all fields are always quoted, otherwise a field is only quoted if it contains a quotation mark, delimiter, line feed or carriage return
escapeCharacter - the character used to escape quotation marks and itself in the output
lineSeparator - the line termination character
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(Object value)
           throws IOException
Description copied from interface: RecordWriter
Writes a record object to this output stream.

Specified by:
write in interface RecordWriter
Parameters:
value - the record object to write
Throws:
IOException - if an I/O error occurs writing the record to the stream

write

public void write(String[] record)
           throws IOException
Formats and writes a record to this output stream.

Parameters:
record - the record to write
Throws:
IOException - if an I/O error occurs

flush

public void flush()
           throws IOException
Description copied from interface: RecordWriter
Flushes the output stream.

Specified by:
flush in interface RecordWriter
Throws:
IOException - if an I/O error occurs flushing the stream

close

public void close()
           throws IOException
Description copied from interface: RecordWriter
Closes the output stream.

Specified by:
close in interface RecordWriter
Throws:
IOException - if an I/O error occurs closing the stream

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim