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 voidclose()Closes the writer.protected java.lang.Stringconvert(java.lang.Object value)Converts the value to its string representation.protected java.lang.Stringconvert(java.lang.String type, java.lang.Object value)Converts the value to its string representation.intgetRowCount()Returns the rows written.protected TypeConversionHandlergetTypeConversionHandler(java.lang.String type)Returns a type conversion handler for the given type.protected intincrementRowCount()Increments the row count.protected voidinit()General initialization.voidprintComment(java.lang.String comment)Prints a comment into the output stream.voidprintComment(java.lang.String comment, int row, int column)Prints a comment into the output stream.voidprintRow(java.util.Collection<?> columns)Prints a single row into the CSV stream.voidprintRow(java.util.Iterator<?> columns)Prints a new row into the CSV stream.voidprintRow(java.util.Iterator<?> columns, int size)Prints a single row into the CSV stream.voidregisterTypeConversionHandler(TypeConversionHandler handler)Registers a type conversion handler.voidunregisterTypeConversionHandler(TypeConversionHandler handler)Unregisters a type conversion handler.
-
Constructor Details
-
AbstractTableWriter
public AbstractTableWriter()
-
-
Method Details
-
init
protected void init()General initialization. This implementation does nothing. -
printComment
public void printComment(java.lang.String comment) throws java.io.IOExceptionPrints a comment into the output stream. This implementation does nothing by default.- Specified by:
printCommentin interfaceTableWriter- 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.IOExceptionPrints a comment into the output stream. This implementation does nothing by default.- Specified by:
printCommentin interfaceTableWriter- Parameters:
comment- the comment to writerow- index of row for commentcolumn- 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:
closein interfaceTableWriter
-
getRowCount
public int getRowCount()Returns the rows written.- Returns:
- the rowCount
-
incrementRowCount
protected int incrementRowCount()Increments the row count.- Returns:
- current row count
-
registerTypeConversionHandler
Registers a type conversion handler.- Parameters:
handler- handler to register
-
unregisterTypeConversionHandler
Unregisters a type conversion handler.- Parameters:
handler- handler to unregister
-
getTypeConversionHandler
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 returnedvalue- object- Returns:
- string representation
-
printRow
public void printRow(java.util.Collection<?> columns) throws java.io.IOExceptionPrints 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:
printRowin interfaceTableWriter- 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.IOExceptionPrints a single row into the CSV stream. The columns are written to the CSV stream as delivered by the iterator.- Specified by:
printRowin interfaceTableWriter- 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.IOExceptionPrints a new row into the CSV stream. The columns are written to the CSV stream as delivered by the iterator.- Specified by:
printRowin interfaceTableWriter- Parameters:
columns- iterator that returns column values.- Throws:
java.io.IOException- when an exception occurs
-