Class DelimitedWriter

  • All Implemented Interfaces:
    RecordWriter

    public class DelimitedWriter
    extends java.lang.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
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DelimitedWriter

        public DelimitedWriter​(java.io.Writer out)
        Constructs a new DelimitedWriter.
        Parameters:
        out - the output stream to write to
      • DelimitedWriter

        public DelimitedWriter​(java.io.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​(java.io.Writer out,
                               DelimitedParserConfiguration config)
        Constructs a new DelimitedWriter.
        Parameters:
        out - the output stream to write to
        config - 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 interface RecordWriter
        Parameters:
        value - the record object to write
        Throws:
        java.io.IOException - if an I/O error occurs writing the record to the stream
        RecordIOException
      • 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 interface RecordWriter
        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 interface RecordWriter
        Throws:
        java.io.IOException - if an I/O error occurs closing the stream