Class TextTableWriter


public class TextTableWriter extends TextWriter
Writes records as an easy-to-read, plain-text table with padded, aligned columns — a header row of field names, a dashed separator line, then one row per record:
 Name             Account ID  Account Balance
 ---------------  ----------  ---------------
 Richard Winters  MJ-01       10567.25
 Lewis Nixon      LT-01       -298.1
 

Columns are the union of field names across all records in first-seen order; rows leave a blank cell where a record has no value for a column. Records are buffered in memory until this writer closes so column names and widths can be computed across the whole set — the table is only written on close().

  • Constructor Details

    • TextTableWriter

      public TextTableWriter(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.
    • TextTableWriter

      public TextTableWriter(File file)
    • TextTableWriter

      public TextTableWriter(Writer writer)
  • Method Details

    • getNewLine

      public String getNewLine()
      Returns the string used between each line (defaults to the platform's line separator).
    • setNewLine

      public TextTableWriter setNewLine(String newLine)
      Assigns the string used between each line (defaults to "\n" on Linux and "\r\n" on Windows).
    • getColumnSeparator

      public String getColumnSeparator()
      Returns the string written between columns (defaults to two spaces).
    • setColumnSeparator

      public TextTableWriter setColumnSeparator(String columnSeparator)
      Assigns the string written between columns (defaults to two spaces).
    • writeRecord

      protected void writeRecord(Record record) throws Throwable
      Description copied from class: AbstractWriter
      Writes one row; called first for the header row (see AbstractWriter.isHeaderRow()) when field names are written, then for each record.
      Specified by:
      writeRecord in class AbstractWriter
      Throws:
      Throwable
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class TextWriter
    • 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 TextWriter