Package csv.impl

Class AbstractTableWriter

java.lang.Object
csv.impl.AbstractTableWriter
All Implemented Interfaces:
TableWriter
Direct Known Subclasses:
AbstractStreamTableWriter

public abstract class AbstractTableWriter extends Object implements TableWriter
Abstract implementation of writer interface. The interface provides basic functionality being needed regardless of underlying medium to be written to.
Author:
ralph
  • Constructor Details

    • AbstractTableWriter

      public AbstractTableWriter()
  • Method Details

    • init

      protected void init()
      General initialization. This implementation does nothing.
    • getMapper

      public StreamMapper getMapper()
      Returns the mapper.
      Returns:
      the mapper
    • setMapper

      public void setMapper(StreamMapper mapper)
      Sets the mapper.
      Parameters:
      mapper - the mapper to set
    • printComment

      public void printComment(String comment) throws IOException
      Prints a comment into the output stream. This implementation does nothing by default.
      Specified by:
      printComment in interface TableWriter
      Parameters:
      comment - the comment to write
      Throws:
      IOException - when an exception occurs
    • printComment

      public void printComment(String comment, int row, int column) throws IOException
      Prints a comment into the output stream. This implementation does nothing by default.
      Specified by:
      printComment in interface TableWriter
      Parameters:
      comment - the comment to write
      row - index of row for comment
      column - index of column for comment
      Throws:
      IOException - when an exception occurs
    • close

      public void close()
      Closes the writer. This implementation does nothing.
      Specified by:
      close in interface TableWriter
    • getRowCount

      public int getRowCount()
      Returns the rows written.
      Returns:
      the rowCount
    • incrementRowCount

      protected int incrementRowCount()
      Increments the row count.
      Returns:
      current row count
    • convert

      protected Object convert(Object value)
      Converts the value to its stream representation.
      Parameters:
      value - object
      Returns:
      stream representation
    • printRow

      public void printRow(Collection<?> columns) throws IOException
      Prints a single row into the CSV stream. The columns are written to the CSV stream as the are delivered by the collection's iterator.
      Specified by:
      printRow in interface TableWriter
      Parameters:
      columns - collection of column values. An iterator will be used to retrieve values from the collection.
      Throws:
      IOException - when an exception occurs
    • printRow

      public void printRow(Iterator<?> columns, int size) throws IOException
      Prints a single row into the CSV stream. The columns are written to the CSV stream as delivered by the iterator.
      Specified by:
      printRow in interface TableWriter
      Parameters:
      columns - iterator that returns column values.
      size - number of values to retrieve from iterator. Method will abort at this size.
      Throws:
      IOException - when an exception occurs
    • printRow

      public void printRow(Iterator<?> columns) throws IOException
      Prints a new row into the CSV stream. The columns are written to the CSV stream as delivered by the iterator.
      Specified by:
      printRow in interface TableWriter
      Parameters:
      columns - iterator that returns column values.
      Throws:
      IOException - when an exception occurs