Class TextWriter

Direct Known Subclasses:
H2InsertWriter, JsonWriter, LatexWriter, LinedTextWriter, MySqlInsertWriter, PostgreSqlInsertWriter, SimpleJsonWriter, SimpleXmlWriter, TemplateWriter, TextTableWriter, XmlWriter

public abstract class TextWriter extends AbstractWriter
Abstract super-class for writing records to a text stream. Unike TextStreamWriter, this writer has the concept of fieldNamesInFirstRow and assumes the output is line based.
  • Constructor Details

    • TextWriter

      public TextWriter(File file, boolean append)
      Parameters:
      file -
      append - Indicates if writing should start at the end of the file (if it exists). If the specified file exists and has contents (more than 0 bytes), then the fieldNamesInFirstRow property will be set to false.
    • TextWriter

      public TextWriter(File file)
      Creates a writer that overwrites the file, which this constructor opens immediately rather than in open().
    • TextWriter

      public TextWriter(Writer writer)
  • Method Details

    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class AbstractWriter
    • getWriter

      public BufferedWriter getWriter()
    • getFile

      public File getFile()
      Returns the target file or null if this writer was created from a Writer.
    • isFieldNamesInFirstRow

      public boolean isFieldNamesInFirstRow()
      Description copied from class: AbstractWriter
      Indicates if a header row of field names is written before the first record (default is true).
      Overrides:
      isFieldNamesInFirstRow in class AbstractWriter
    • isAppend

      public boolean isAppend()
      Indicates if writing should start at the end of the file (if it exists). If the specified file exists and has contents (more than 0 bytes), then the fieldNamesInFirstRow property will be set to false.
      See Also:
    • isAutoCloseWriter

      public boolean isAutoCloseWriter()
      Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).
    • setAutoCloseWriter

      public TextWriter setAutoCloseWriter(boolean autoCloseWriter)
      Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).
    • isFlushOnWrite

      public boolean isFlushOnWrite()
      Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written.
    • setFlushOnWrite

      public TextWriter setFlushOnWrite(boolean flushOnWrite)
      Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written (defaults to false).
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
    • write

      public void write(Record record) throws DataException
      Description copied from class: DataWriter
      Writes the specified record to this DataWriter and increases the record-count by 1. Any exception raised while writing will be converted to a DataException using DataObject.exception(Throwable).

      Subclasses generally do not need to override this method, instead they should implement DataWriter.writeImpl(Record).

      Overrides:
      write in class AbstractWriter
      Throws:
      DataException