net.sourceforge.jdbcexporter.formatter
Class FixedDelimiterFormatter

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

public class FixedDelimiterFormatter
extends java.lang.Object
implements DelimiterFormatter

The FixedDelimiterFormatter class implements the DelimiterFormatter interface to format column values in a fixed file format. Each column value is placed into a section of the line (specified by the columnPositions property).

Since:
0.6
Author:
Chris Nagy

Field Summary
protected  int[][] columnPositions
          The number range for each column.
protected  int length
          The length of each row in the file.
protected  java.io.Writer writer
          The output writer.
 
Constructor Summary
FixedDelimiterFormatter()
           
 
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.
 void setColumnPositions(int[][] positions)
          Sets the number range for each column value.
 void setLength(int len)
          Sets the length of each row.
 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

writer

protected java.io.Writer writer
The output writer.


columnPositions

protected int[][] columnPositions
The number range for each column.


length

protected int length
The length of each row in the file.

Constructor Detail

FixedDelimiterFormatter

public FixedDelimiterFormatter()
Method Detail

setColumnPositions

public void setColumnPositions(int[][] positions)
Sets the number range for each column value. A number range is specified by two numbers : the starting position and the ending position). The size of the first dimension should be equal to the number of columns to be formatted. The size of the second dimension should be 2, where the first value is the starting position and the second value is the ending position. The starting position should be greater then the ending position and the both values should be greater than zero. Example:
 setColumnPositions( new int[][] { { 1, 5 }, { 16, 20 }, { 6, 15 } } )
 
This will setup the FixedDelimiterFormatter to format three column values: the first column value will be stored from the 1st character to the 5th character, the second column value will be stored from the 15th character to the 20th character, and the last column value will be stored from the 6th character to the 15th character.

Parameters:
positions - the number ranges for all column values

setLength

public void setLength(int len)
Sets the length of each row. If rows are longer then this value then they are truncated. If rows are shorter then spaces are appended.

Parameters:
len - the length
Since:
0.61

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)

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()