Class ColumnFormatter


  • public class ColumnFormatter
    extends Object
    Simple output formatter for column-oriented data, writing its output to a PrintWriter object. Handles escaping of the column data so that the resulting output is unambiguous and reasonably safe and machine parsable.
    • Constructor Detail

      • ColumnFormatter

        public ColumnFormatter​(PrintWriter out,
                               char columnSeparator)
        Parameters:
        out - The writer to which output should be sent.
        columnSeparator - A character that should serve as the separator token between columns of output. As only non-printable characters in the column text are ever escaped, the column separator must be a non-printable character if the output needs to be unambiguously parsed.
    • Method Detail

      • addColumn

        public void addColumn​(String content)
        Adds a text string as a new column in the current line of output, taking care of escaping as necessary.
        Parameters:
        content - the string to add.
      • finish

        public void finish()
        Finishes the output by flushing the current line and takes care of any other cleanup action.
      • nextLine

        public void nextLine()
        Flushes the current line of output and makes the formatter ready to start receiving new column data for a new line (or end-of-file). If the current line is empty nothing is done, i.e. consecutive calls to this method without intervening calls to addColumn(java.lang.String) will be squashed.