Package csv.impl

Class AbstractTableWriter

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

public abstract class AbstractTableWriter
extends java.lang.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 Summary

    Constructors 
    Constructor Description
    AbstractTableWriter()  
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes the writer.
    protected java.lang.String convert​(java.lang.Object value)
    Converts the value to its string representation.
    protected java.lang.String convert​(java.lang.String type, java.lang.Object value)
    Converts the value to its string representation.
    int getRowCount()
    Returns the rows written.
    protected TypeConversionHandler getTypeConversionHandler​(java.lang.String type)
    Returns a type conversion handler for the given type.
    protected int incrementRowCount()
    Increments the row count.
    protected void init()
    General initialization.
    void printComment​(java.lang.String comment)
    Prints a comment into the output stream.
    void printComment​(java.lang.String comment, int row, int column)
    Prints a comment into the output stream.
    void printRow​(java.util.Collection<?> columns)
    Prints a single row into the CSV stream.
    void printRow​(java.util.Iterator<?> columns)
    Prints a new row into the CSV stream.
    void printRow​(java.util.Iterator<?> columns, int size)
    Prints a single row into the CSV stream.
    void registerTypeConversionHandler​(TypeConversionHandler handler)
    Registers a type conversion handler.
    void unregisterTypeConversionHandler​(TypeConversionHandler handler)
    Unregisters a type conversion handler.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface csv.TableWriter

    printRow
  • Constructor Details

  • Method Details

    • init

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

      public void printComment​(java.lang.String comment) throws java.io.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:
      java.io.IOException - when an exception occurs
    • printComment

      public void printComment​(java.lang.String comment, int row, int column) throws java.io.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:
      java.io.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
    • registerTypeConversionHandler

      public void registerTypeConversionHandler​(TypeConversionHandler handler)
      Registers a type conversion handler.
      Parameters:
      handler - handler to register
    • unregisterTypeConversionHandler

      public void unregisterTypeConversionHandler​(TypeConversionHandler handler)
      Unregisters a type conversion handler.
      Parameters:
      handler - handler to unregister
    • getTypeConversionHandler

      protected TypeConversionHandler getTypeConversionHandler​(java.lang.String type)
      Returns a type conversion handler for the given type.
      Parameters:
      type - type to get a handler for
      Returns:
      conversion handler
    • convert

      protected java.lang.String convert​(java.lang.Object value)
      Converts the value to its string representation.
      Parameters:
      value - object
      Returns:
      string representation
    • convert

      protected java.lang.String convert​(java.lang.String type, java.lang.Object value)
      Converts the value to its string representation.
      Parameters:
      type - type of object being returned
      value - object
      Returns:
      string representation
    • printRow

      public void printRow​(java.util.Collection<?> columns) throws java.io.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:
      java.io.IOException - when an exception occurs
    • printRow

      public void printRow​(java.util.Iterator<?> columns, int size) throws java.io.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:
      java.io.IOException - when an exception occurs
    • printRow

      public void printRow​(java.util.Iterator<?> columns) throws java.io.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:
      java.io.IOException - when an exception occurs