Arch4J 1.1

org.arch4j.parse
Class RecordReader

java.lang.Object
  |
  +--org.arch4j.parse.RecordReader
Direct Known Subclasses:
DelimitedRecordReader, FixedRecordReader

public abstract class RecordReader
extends Object


Field Summary
static String DATA_TYPE_DATE
           
static String DATA_TYPE_NUMBER
           
static String DATA_TYPE_TEXT
           
protected  ReadOnlyProperty format
          property tree, specific to each record reader subclass.
 
Constructor Summary
RecordReader()
           
 
Method Summary
protected  Object convertType(String textValue, String type, String dateFormat)
          convert a text value to a given type.
protected abstract  RecordData createRecord(String[] rawBuffer)
          create an RecordData object from a raw data buffer, based on the format properties.
protected abstract  String[] getRawRecord(BufferedReader reader, String[] rawBuffer)
          get the next set of raw data from the input stream, or return null if at the end of the stream.
protected abstract  void initFormatData()
           
 void read(InputStream input, OutputStream reject, InputRecordHandler handler)
          read raw data records from an input stream, convert them to RecordData objects using the format properties, and notify the handler provided.
protected  void rejectRecord(String[] rawData, String rejectMessage, BufferedWriter rejectWriter)
          send a rejected record to the reject stream
protected  String removeQuotes(String qStr)
           
 void setFormat(ReadOnlyProperty formatProps)
          provide the readed with the property tree that defines the format of the files it must read.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_TYPE_TEXT

public static final String DATA_TYPE_TEXT
See Also:
Constant Field Values

DATA_TYPE_DATE

public static final String DATA_TYPE_DATE
See Also:
Constant Field Values

DATA_TYPE_NUMBER

public static final String DATA_TYPE_NUMBER
See Also:
Constant Field Values

format

protected ReadOnlyProperty format
property tree, specific to each record reader subclass.

Constructor Detail

RecordReader

public RecordReader()
Method Detail

setFormat

public void setFormat(ReadOnlyProperty formatProps)
               throws FormatException
provide the readed with the property tree that defines the format of the files it must read.

Parameters:
formatProps - property tree defining file format. See subclass implementations.
FormatException

read

public void read(InputStream input,
                 OutputStream reject,
                 InputRecordHandler handler)
          throws IOException,
                 FormatException
read raw data records from an input stream, convert them to RecordData objects using the format properties, and notify the handler provided. Send any edit/reject reject records to the specified reject stream.

Parameters:
input - source of raw record data
reject - desitination for raw data of rejected records
handler - object to be notified with results of each record read
IOException
FormatException

rejectRecord

protected void rejectRecord(String[] rawData,
                            String rejectMessage,
                            BufferedWriter rejectWriter)
                     throws IOException
send a rejected record to the reject stream

Parameters:
rawData - raw character data of rejected record
rejectWriter - a writer servicing the reject output stream
IOException

convertType

protected Object convertType(String textValue,
                             String type,
                             String dateFormat)
                      throws RecordDataInputException,
                             FormatException
convert a text value to a given type. Types supported include Text, Date Number. Text values are returned as String objects, Date values are returned as Date objects, and Number values are returned as BigDecimal objects.

Parameters:
textValue - text representation of the desired value
type - string giving the type to convert to - Text, Date, Number
dateFormat - format in the form that SimpleDateFormat expects. For example "yyyyMMdd" or "MM/dd/yy".
Returns:
convered value.
RecordDataInputException
FormatException

removeQuotes

protected String removeQuotes(String qStr)

getRawRecord

protected abstract String[] getRawRecord(BufferedReader reader,
                                         String[] rawBuffer)
                                  throws RecordDataInputException,
                                         IOException
get the next set of raw data from the input stream, or return null if at the end of the stream.

Parameters:
reader - buffered reader servicing the raw data input stream.
rawBuffer - raw data buffer to reuse for this record if possible. Could be null.
Returns:
filled raw data buffer
Throws:
RecordDataInputExceptoin - if the necessary data cannot be retreived
RecordDataInputException
IOException

createRecord

protected abstract RecordData createRecord(String[] rawBuffer)
                                    throws FormatException,
                                           RecordDataInputException
create an RecordData object from a raw data buffer, based on the format properties.

Parameters:
rawBuffer - raw record data
Returns:
populated record object
Throws:
FormatException - when there is a fundamental problem with the record format definition and all processing should cease.
RecordDataInputException - when there is a problem retreiving data from this record, but processing of further records can continue.

initFormatData

protected abstract void initFormatData()
                                throws FormatException
FormatException

Arch4J 1.1

Copyright © 2000-2004 SpiderLogic, a service of Wipfli Ullrich Bertelson LLP.