org.jmonks.batch.io
Class FileWriter

java.lang.Object
  extended byorg.jmonks.batch.io.FileWriter
Direct Known Subclasses:
FlatFileWriter, XMLFileWriter

public abstract class FileWriter
extends java.lang.Object

FileWriter writes the specified file based on the given file spec with the data written in the form of WriterRecord's. This provides the methods to create the required records and write them into the file writer. Once finished writing of all the records file writer should be closed by calling the appropriate methods. This provides the factory method to create the file writer based on the file spec. Here is a sample code snippet to use the file writer.

      InputStream fileSpecInputStream=...;
      OutputStream fileOutputStream=...;
      FileWriter fileWriter=FileWriter.getFileWriter(fileOutputStream,fileSpecInputStream);
      WriterRecord record=fileWriter.createWriterRecord(RecordType.DETAIL);
      record.writeField("consumer-id","123456");
      //Write the other field values.
      fileWriter.writeRecord(record);
      fileWriter.close();
  

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Constructor Summary
FileWriter()
           
 
Method Summary
abstract  void close()
          Closes the writer and releases all the resources associated with the writer.
abstract  WriterRecord createWriterRecord(RecordType recordType)
          Creates the writer record to be used to fill all the field values and submit to the file writer to write the record into the file.
static FileWriter getFileWriter(java.io.OutputStream outputStream, FileSpec fileSpec)
           Factory method to get the file writer.
static FileWriter getFileWriter(java.io.OutputStream outputStream, java.io.InputStream fileSpecInputStream)
           Factory method to get the file writer.
static FileWriter getFileWriter(java.io.Writer writer, FileSpec fileSpec)
           Factory method to get the file writer.
static FileWriter getFileWriter(java.io.Writer writer, java.io.InputStream fileSpecInputStream)
           Factory method to get the file writer.
abstract  void writeRecord(WriterRecord record)
          Writes the given record into the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileWriter

public FileWriter()
Method Detail

writeRecord

public abstract void writeRecord(WriterRecord record)
Writes the given record into the file. The record should be obtained from this file writer using the createWriterRecord method.

Parameters:
record - WriterRecord that you want to write into the file.
Throws:
FileParseException - Problems while writing the record into file.

close

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


createWriterRecord

public abstract WriterRecord createWriterRecord(RecordType recordType)
Creates the writer record to be used to fill all the field values and submit to the file writer to write the record into the file.

Parameters:
recordType - Type of record.
Returns:
Retruns the writer record.
Throws:
java.lang.IllegalArgumentException - If given record type is not associated with any record spec.

getFileWriter

public static FileWriter getFileWriter(java.io.OutputStream outputStream,
                                       java.io.InputStream fileSpecInputStream)

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

Parameters:
outputStream - Output stream to write the records.
fileSpecInputStream - Input stream to read the file spec.
Returns:
Returns the appropriate writer.
Throws:
java.lang.IllegalArgumentException - If the given file output stream or file spec input stream is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.

getFileWriter

public static FileWriter getFileWriter(java.io.OutputStream outputStream,
                                       FileSpec fileSpec)

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

Parameters:
outputStream - Output stream to write the records.
fileSpec - File spec to be used to create the writer.
Returns:
Returns the appropriate writer.
Throws:
java.lang.IllegalArgumentException - If the given file output stream or file spec is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.

getFileWriter

public static FileWriter getFileWriter(java.io.Writer writer,
                                       java.io.InputStream fileSpecInputStream)

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

Parameters:
writer - Writer to write the records.
fileSpecInputStream - Input stream to read the file spec.
Returns:
Returns the appropriate writer.
Throws:
java.lang.IllegalArgumentException - If the given file output stream or file spec input stream is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.

getFileWriter

public static FileWriter getFileWriter(java.io.Writer writer,
                                       FileSpec fileSpec)

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

Parameters:
writer - Writer to write the records.
fileSpec - File spec to be used to create the writer.
Returns:
Returns the appropriate writer.
Throws:
java.lang.IllegalArgumentException - If the given file output stream or file spec is null.
FileSpecException - If the configured file type in file spec doesnt exist in FileType class.