BeanIO 1.2.3

org.beanio.stream.delimited
Class DelimitedWriter

java.lang.Object
  extended by org.beanio.stream.delimited.DelimitedWriter
All Implemented Interfaces:
RecordWriter

public class DelimitedWriter
extends Object
implements RecordWriter

A DelimitedWriter is used to write records to delimited flat files. Each record must be a String array of fields. By default, fields are delimited by the tab character, but any other single character may be configured instead.

If an escape character is configured, any field containing the delimiter will be escaped by placing the escape character immediately before the delimiter. For example, if the record "Field1,2", "Field3" is written using a comma delimiter and backslash escape character, the following text will be written to the output stream:

 Field1\,2,Field3
 
Note that no validation is performed when a record is written, so if an escape character is not configured and a field contains a delimiting character, the generated output may be invalid.

Since:
1.0
Author:
Kevin Seim

Constructor Summary
DelimitedWriter(Writer out)
          Constructs a new DelimitedWriter.
DelimitedWriter(Writer out, char delimiter)
          Constructs a new DelimitedWriter.
DelimitedWriter(Writer out, char delimiter, Character escape)
          Constructs a new DelimitedWriter.
DelimitedWriter(Writer out, char delimiter, Character escape, String recordTerminator)
          Constructs a new DelimitedWriter.
 
Method Summary
 void close()
          Closes the output stream.
 void flush()
          Flushes the output stream.
 void write(Object value)
          Writes a record object to this output stream.
 void write(String[] record)
          Writes a record to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelimitedWriter

public DelimitedWriter(Writer out)
Constructs a new DelimitedWriter.

Parameters:
out - the output stream to write to

DelimitedWriter

public DelimitedWriter(Writer out,
                       char delimiter)
Constructs a new DelimitedWriter. By default, the escape character is disabled.

Parameters:
out - the output stream to write to
delimiter - the field delimiting character

DelimitedWriter

public DelimitedWriter(Writer out,
                       char delimiter,
                       Character escape)
Constructs a new DelimitedWriter.

Parameters:
out - the output stream to write to
delimiter - the field delimiting character
escape - the escape character, or null to disable escaping

DelimitedWriter

public DelimitedWriter(Writer out,
                       char delimiter,
                       Character escape,
                       String recordTerminator)
Constructs a new DelimitedWriter.

Parameters:
out - the output stream to write to
delimiter - the field delimiting character
escape - the escape character, or null to disable escaping
recordTerminator - the termination sequence to use at the end of each record
Method Detail

write

public void write(Object value)
           throws IOException,
                  RecordIOException
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
RecordIOException

write

public void write(String[] record)
           throws IOException
Writes a record to the 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