org.jmonks.batch.io.flat
Class FlatFileReader

java.lang.Object
  extended byorg.jmonks.batch.io.FileReader
      extended byorg.jmonks.batch.io.flat.FlatFileReader
Direct Known Subclasses:
DelimitedFlatFileReader, FixedWidthFlatFileReader

public abstract class FlatFileReader
extends FileReader

FlatFileReader reads the specified fixed width flat file according to the given file spec and returns the recrods on the needed basis. Each field value from the record should be read using readField method by passing the fieldName mentioned in the file spec. To find out how to read each record from the file and to read the each field from the record, refer to the FileReader javadoc.

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Nested Class Summary
 class FlatFileReader.FlatFileReaderRecord
          FixedWidthFlatFileReaderRecord implements ReaderRecord by maintaing the field names and values as a map and provides the methods with proper access privileges to read into and write from the record.
 
Field Summary
protected  FileSpec fileSpec
          File spec to be used to read the flat file.
 
Constructor Summary
FlatFileReader(java.io.InputStream fileInputStream, FileSpec fileSpec)
          Constructs and initializes the flat file reader with the given file path and file spec.
FlatFileReader(java.io.Reader reader, FileSpec fileSpec)
          Constructs and initializes the flat file reader with the given file path and file spec.
 
Method Summary
 void close()
          Closes the reader and all the resources it is using.
 ReaderRecord getNextRecord()
           Gets the next available record from the file and returns it wrapped with the appropriate ReaderRecod object to easily access the data fields from the record.
protected abstract  ReaderRecord parseRecord(java.lang.String recordString)
          Parses the given record string based on the record spec, translates it into the appropriate ReaderRecord and returns that reader record.
 
Methods inherited from class org.jmonks.batch.io.FileReader
getFileReader, getFileReader, getFileReader, getFileReader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileSpec

protected FileSpec fileSpec
File spec to be used to read the flat file.

Constructor Detail

FlatFileReader

public FlatFileReader(java.io.InputStream fileInputStream,
                      FileSpec fileSpec)
Constructs and initializes the flat file reader with the given file path and file spec.

Parameters:
fileInputStream - Input stream to the file.
fileSpec - File spec to be used to read the file.

FlatFileReader

public FlatFileReader(java.io.Reader reader,
                      FileSpec fileSpec)
Constructs and initializes the flat file reader with the given file path and file spec.

Parameters:
reader - Reader to the file.
fileSpec - File spec to be used to read the file.
Method Detail

getNextRecord

public ReaderRecord getNextRecord()

Gets the next available record from the file and returns it wrapped with the appropriate ReaderRecod object to easily access the data fields from the record. If you defined multiple record specs, make sure to verify the recrod type before you read the values.

Specified by:
getNextRecord in class FileReader
Returns:
Returns the next available record.
Throws:
FileParseException - Problems while parsing the next record. This includes unable to identify the recod with the availble record specs.

close

public void close()
Closes the reader and all the resources it is using. This includes the input stream passed to create the reader.

Specified by:
close in class FileReader

parseRecord

protected abstract ReaderRecord parseRecord(java.lang.String recordString)
Parses the given record string based on the record spec, translates it into the appropriate ReaderRecord and returns that reader record.

Parameters:
recordString - Next available line read from the file.
Throws:
FileParseException - Problems while parsing the next record. This includes unable to identify the recod with the availble record specs.