net.sourceforge.jdbcexporter.formatter
Class CSVDelimiterFormatter

java.lang.Object
  extended bynet.sourceforge.jdbcexporter.formatter.CSVDelimiterFormatter
All Implemented Interfaces:
DelimiterFormatter

public class CSVDelimiterFormatter
extends java.lang.Object
implements DelimiterFormatter

The CSVDelimiterFormatter class implements the DelimiterFormatter interface to format column values in a character delimiter format. Each column value is separated from another column value by a character or set of characters (ex. ','). In addition, the CSVDelimiterFormatter supports the ability to enclose each column value with a character or set of characters (ex. '"' ).

Since:
0.6
Author:
Chris Nagy

Field Summary
protected  java.lang.String columnDelimiter
          The character(s) that separate each column value.
protected  int[] emptyPositions
          Sets the positions, in the csv, to place empty strings as their values.
protected  java.lang.String enclosedDelimiter
          The character(s) that enclose each column value.
protected  boolean enclosedOptional
          The flag indicating each column value must be enclosed by the set of characters defined.
protected  java.lang.String header
          The initial contents of the file.
protected  boolean writeHeader
          Flag to indicate that the header should be written before the next row is.
 
Constructor Summary
CSVDelimiterFormatter()
           
 
Method Summary
 void finish()
          Finishs the writing of rows to the output source.
 java.lang.String formatValues(ColumnValue[] values)
          Creates a string representing the row of column values.
 java.lang.String getColumnDelimiter()
          Returns the character(s) that separate each column value.
 java.lang.String getEnclosedDelimiter()
          Returns the character(s) that enclose each column value.
 java.lang.String getHeader()
          Returns the header of the output file.
 boolean isEnclosedOptional()
          Returns whether each column value must be enclosed by the set of characters defined.
 void setColumnDelimiter(java.lang.String delimiter)
          Sets the character(s) that separate each column value.
 void setEmptyPositions(int[] positions)
          Sets the positions, in the csv, to place empty strings as their values.
 void setEnclosedDelimiter(java.lang.String delimiter)
          Sets the character(s) that enclose each column value.
 void setEnclosedOptional(boolean optional)
          Sets that each column value must be enclosed by the set of characters defined.
 void setHeader(java.lang.String header)
          Sets the header of the output file.
 void setWriter(java.io.Writer output)
          Sets the output source for the formatter.
 void writeNextRow(java.lang.String row)
          Writes the next row to the output source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columnDelimiter

protected java.lang.String columnDelimiter
The character(s) that separate each column value.


enclosedDelimiter

protected java.lang.String enclosedDelimiter
The character(s) that enclose each column value.


enclosedOptional

protected boolean enclosedOptional
The flag indicating each column value must be enclosed by the set of characters defined.


emptyPositions

protected int[] emptyPositions
Sets the positions, in the csv, to place empty strings as their values.


header

protected java.lang.String header
The initial contents of the file.

Since:
0.74

writeHeader

protected boolean writeHeader
Flag to indicate that the header should be written before the next row is.

Since:
0.74
Constructor Detail

CSVDelimiterFormatter

public CSVDelimiterFormatter()
Method Detail

setColumnDelimiter

public void setColumnDelimiter(java.lang.String delimiter)
Sets the character(s) that separate each column value.

Parameters:
delimiter - the column value delimiter.

getColumnDelimiter

public java.lang.String getColumnDelimiter()
Returns the character(s) that separate each column value.

Returns:
the column value delimiter

setEnclosedDelimiter

public void setEnclosedDelimiter(java.lang.String delimiter)
Sets the character(s) that enclose each column value.

Parameters:
delimiter - the enclose delimiter

getEnclosedDelimiter

public java.lang.String getEnclosedDelimiter()
Returns the character(s) that enclose each column value.

Returns:
the enclose delimiter

setEnclosedOptional

public void setEnclosedOptional(boolean optional)
Sets that each column value must be enclosed by the set of characters defined.

Parameters:
optional - boolean flag indicating that each column value must be enclosed.

isEnclosedOptional

public boolean isEnclosedOptional()
Returns whether each column value must be enclosed by the set of characters defined.

Returns:
boolean flag indicating that each column value must be enclosed.

setHeader

public void setHeader(java.lang.String header)
Sets the header of the output file.

Parameters:
header - The initial contents of the file
Since:
0.74

getHeader

public java.lang.String getHeader()
Returns the header of the output file.

Returns:
The initial contents of the file
Since:
0.74

setWriter

public void setWriter(java.io.Writer output)
Description copied from interface: DelimiterFormatter
Sets the output source for the formatter.

Specified by:
setWriter in interface DelimiterFormatter
Parameters:
output - the destination of the data
See Also:
DelimiterFormatter.setWriter(java.io.Writer)

setEmptyPositions

public void setEmptyPositions(int[] positions)
Sets the positions, in the csv, to place empty strings as their values.

Parameters:
positions - a comma-separated list of positions (first position = 1)
Since:
0.61

formatValues

public java.lang.String formatValues(ColumnValue[] values)
Description copied from interface: DelimiterFormatter
Creates a string representing the row of column values.

Specified by:
formatValues in interface DelimiterFormatter
Parameters:
values - the column values
Returns:
the string
See Also:
DelimiterFormatter.formatValues(net.sourceforge.jdbcimporter.ColumnValue[])

writeNextRow

public void writeNextRow(java.lang.String row)
                  throws java.io.IOException
Description copied from interface: DelimiterFormatter
Writes the next row to the output source.

Specified by:
writeNextRow in interface DelimiterFormatter
Parameters:
row - the next row
Throws:
java.io.IOException - if an error occurs while writing the next row
See Also:
DelimiterFormatter.writeNextRow(java.lang.String)

finish

public void finish()
            throws java.io.IOException
Description copied from interface: DelimiterFormatter
Finishs the writing of rows to the output source.

Specified by:
finish in interface DelimiterFormatter
Throws:
java.io.IOException
See Also:
DelimiterFormatter.finish()