net.sourceforge.jdbcimporter.parser
Class FixedDelimiterParser

java.lang.Object
  extended bynet.sourceforge.jdbcimporter.parser.FixedDelimiterParser
All Implemented Interfaces:
DelimiterParser

public class FixedDelimiterParser
extends java.lang.Object
implements DelimiterParser

The FixedDelimiterParser class implements the DelimiterParser interface to parse column values from a fixed file format. Each column value is taken from 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 static org.apache.commons.logging.Log LOG
          The log for debug information.
protected  java.io.BufferedReader reader
          The input reader.
 
Constructor Summary
FixedDelimiterParser()
           
 
Method Summary
 java.lang.String getNextRow()
          Returns the next row to be imported as a String.
 ColumnValue[] getValues(java.lang.String nextRow)
          Returns the column values for the row specified.
 void setColumnPositions(int[][] positions)
          Sets the number range for each column value.
 void setLength(int len)
          Sets the length of each row.
 void setReader(java.io.Reader input)
          Sets the input source for the parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static org.apache.commons.logging.Log LOG
The log for debug information.


reader

protected java.io.BufferedReader reader
The input reader.


columnPositions

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


length

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

Constructor Detail

FixedDelimiterParser

public FixedDelimiterParser()
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 parsed. 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 FixedDelimiterParser to parse three column values: the first column value is stored from the 1st character to the 5th character, the second column value is stored from the 15th character to the 20th character, and the last column value is 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.

Parameters:
len - the length
Since:
0.61

setReader

public void setReader(java.io.Reader input)
Description copied from interface: DelimiterParser
Sets the input source for the parser.

Specified by:
setReader in interface DelimiterParser
Parameters:
input - the source of the data to import.
See Also:
DelimiterParser.setReader(Reader)

getNextRow

public java.lang.String getNextRow()
                            throws java.io.IOException
Description copied from interface: DelimiterParser
Returns the next row to be imported as a String.

Specified by:
getNextRow in interface DelimiterParser
Returns:
the next row to import
Throws:
java.io.IOException - if an error occurs while retrieving the next row
See Also:
DelimiterParser.getNextRow()

getValues

public ColumnValue[] getValues(java.lang.String nextRow)
                        throws MalformedDataException
Description copied from interface: DelimiterParser
Returns the column values for the row specified.

Specified by:
getValues in interface DelimiterParser
Parameters:
nextRow - the row to be parsed into column values
Returns:
the column values
Throws:
MalformedDataException - if the row is not formatted properly
See Also:
DelimiterParser.getValues(String)