Package org.beanio.stream.delimited
Class DelimitedWriter
- java.lang.Object
-
- org.beanio.stream.delimited.DelimitedWriter
-
- All Implemented Interfaces:
RecordWriter
public class DelimitedWriter extends java.lang.Object implements RecordWriter
ADelimitedWriter
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
-
-
Constructor Summary
Constructors Constructor Description DelimitedWriter(java.io.Writer out)
Constructs a newDelimitedWriter
.DelimitedWriter(java.io.Writer out, char delimiter)
Constructs a newDelimitedWriter
.DelimitedWriter(java.io.Writer out, DelimitedParserConfiguration config)
Constructs a newDelimitedWriter
.
-
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.void
write(java.lang.Object value)
Writes a record object to this output stream.void
write(java.lang.String[] record)
Writes a record to the output stream.
-
-
-
Constructor Detail
-
DelimitedWriter
public DelimitedWriter(java.io.Writer out)
Constructs a newDelimitedWriter
.- Parameters:
out
- the output stream to write to
-
DelimitedWriter
public DelimitedWriter(java.io.Writer out, char delimiter)
Constructs a newDelimitedWriter
. By default, the escape character is disabled.- Parameters:
out
- the output stream to write todelimiter
- the field delimiting character
-
DelimitedWriter
public DelimitedWriter(java.io.Writer out, DelimitedParserConfiguration config)
Constructs a newDelimitedWriter
.- Parameters:
out
- the output stream to write toconfig
- the delimited parser configuration
-
-
Method Detail
-
write
public void write(java.lang.Object value) throws java.io.IOException, RecordIOException
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 streamRecordIOException
-
write
public void write(java.lang.String[] record) throws java.io.IOException
Writes a record to the 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
-
-