org.jmonks.batch.io
Class FileReader

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

public abstract class FileReader
extends java.lang.Object

FileReader reads the specified file based on the given file spec and returns the data in the form of ReaderRecord's to read the required values referring the field names. This provides the methods to reads the records in an iterative manner. Once finished reading all or required records from the file reader, it should be closed by calling the appropriate methods. This provides the factory method to create the file reader based on the file spec. Here is a sample code snippet to use the file reader.

      InputStream fileSpecInputStream=...; 
      InputStream fileInputStream=....;
      FileReader fileReader=FileReader.getFileReader(fileInputStream,fileSpecInputStream);
      ReaderRecord record=null;
      while((record=fileReader.getNextRecord())!=null)
      {
          if(record.getRecordType()==RecordType.DETAIL)
          {
              String consumerID=record.readField("consumer-id");
              // Read the rest of the fields and does the processing.
          }
      }
      fileReader.close();
  

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Constructor Summary
FileReader()
           
 
Method Summary
abstract  void close()
          Closes the reader and releases all the resources associated with the reader.
static FileReader getFileReader(java.io.InputStream fileInputStream, FileSpec fileSpec)
           Factory method to get the file reader.
static FileReader getFileReader(java.io.InputStream fileInputStream, java.io.InputStream fileSpecInputStream)
           Factory method to get the file reader.
static FileReader getFileReader(java.io.Reader reader, FileSpec fileSpec)
           Factory method to get the file reader.
static FileReader getFileReader(java.io.Reader reader, java.io.InputStream fileSpecInputStream)
           Factory method to get the file reader.
abstract  ReaderRecord getNextRecord()
           Gets the next available record from the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileReader

public FileReader()
Method Detail

getNextRecord

public abstract ReaderRecord getNextRecord()

Gets the next available record from the file. If file doesnt have any more records it returns null.

Returns:
Returns the next available record from the file, null if it doesnt have any more records.
Throws:
FileParseException - Problems while parsing the next record.

close

public abstract void close()
Closes the reader and releases all the resources associated with the reader.


getFileReader

public static FileReader getFileReader(java.io.InputStream fileInputStream,
                                       java.io.InputStream fileSpecInputStream)

Factory method to get the file reader. This method returns the appropriate file reader based on the file type specified in the file spec.

Parameters:
fileInputStream - Input stream to read the data file.
fileSpecInputStream - Input stream to read the file spec.
Returns:
Returns the appropriate reader.
Throws:
java.lang.IllegalArgumentException - If the given fileInputStream or fileSpecInputStream is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.

getFileReader

public static FileReader getFileReader(java.io.InputStream fileInputStream,
                                       FileSpec fileSpec)

Factory method to get the file reader. This method returns the appropriate file reader based on the file type specified in the file spec.

Parameters:
fileInputStream - Input stream to read the data file.
fileSpec - File spec to create the file reader.
Returns:
Returns the appropriate file reader.
Throws:
java.lang.IllegalArgumentException - If the given fileInputStream or fileSpec is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.

getFileReader

public static FileReader getFileReader(java.io.Reader reader,
                                       java.io.InputStream fileSpecInputStream)

Factory method to get the file reader. This method returns the appropriate file reader based on the file type specified in the file spec.

Parameters:
reader - Reader to read the data file.
fileSpecInputStream - Input stream to read the file spec.
Returns:
Returns the appropriate reader.
Throws:
java.lang.IllegalArgumentException - If the given reader or fileSpecInputStream is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.

getFileReader

public static FileReader getFileReader(java.io.Reader reader,
                                       FileSpec fileSpec)

Factory method to get the file reader. This method returns the appropriate file reader based on the file type specified in the file spec.

Parameters:
reader - Reader to read the data file.
fileSpec - File spec to create the file reader.
Returns:
Returns the appropriate reader.
Throws:
java.lang.IllegalArgumentException - If the given reader or fileSpec is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.