org.jmonks.batch.io.flat
Class FlatFileWriter

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

public abstract class FlatFileWriter
extends FileWriter

FlatFileWriter writes/generates the file according to the given file spec with the data submitted in the form of WriterRecord's. This provides the methods to create the required writer records and write the writer record into the file writer. Once finished writing of all the records file writer should be closed by calling the "close" method.

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Nested Class Summary
 class FlatFileWriter.FlatFileWriterRecord
          FixedWidthFlatFileWriterRecord implements WriterRecord 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 in writing the file.
 
Constructor Summary
FlatFileWriter(java.io.OutputStream outputStream, FileSpec fileSpec)
          Constructs and initializes the writer with the given values.
FlatFileWriter(java.io.Writer writer, FileSpec fileSpec)
          Constructs and initializes the writer with the given values.
 
Method Summary
 void close()
          Closes the writer and all the resource being used by this writer.
 WriterRecord createWriterRecord(RecordType recordType)
          Creates the writer record assocites with the given record type.
protected abstract  java.lang.String generateRecord(WriterRecord writerRecord)
          Generates the string representation of the record from given writer record.
 void writeRecord(WriterRecord writerRecord)
          Writes the given record into the file/writer.
 
Methods inherited from class org.jmonks.batch.io.FileWriter
getFileWriter, getFileWriter, getFileWriter, getFileWriter
 
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 in writing the file.

Constructor Detail

FlatFileWriter

public FlatFileWriter(java.io.OutputStream outputStream,
                      FileSpec fileSpec)
Constructs and initializes the writer with the given values.

Parameters:
outputStream - Output stream to write the records.
fileSpec - File spec to be used to generate the file.

FlatFileWriter

public FlatFileWriter(java.io.Writer writer,
                      FileSpec fileSpec)
Constructs and initializes the writer with the given values.

Parameters:
writer - Writer to write the records.
fileSpec - File spec to be used to generate the file.
Method Detail

createWriterRecord

public WriterRecord createWriterRecord(RecordType recordType)
Creates the writer record assocites with the given record type. IllegalArgumentException will be thrown, if there is no record spec is found with this record type.

Specified by:
createWriterRecord in class FileWriter
Parameters:
recordType - Type fo the record to be created.
Returns:
Returns the requested writer record.
Throws:
java.lang.IllegalArgumentException - No record spec is found with this record type.

generateRecord

protected abstract java.lang.String generateRecord(WriterRecord writerRecord)
                                            throws java.io.IOException
Generates the string representation of the record from given writer record.

Parameters:
writerRecord - Record where field values can be read.
Returns:
Returns the string representation of the record.
Throws:
java.io.IOException

writeRecord

public void writeRecord(WriterRecord writerRecord)
Writes the given record into the file/writer.

Specified by:
writeRecord in class FileWriter
Parameters:
writerRecord - Record consist of field names and values.
Throws:
java.lang.IllegalStateException - If writer is closed and trying to write the recrod.
java.lang.IllegalArgumentException - If writer record is null.
FileParseException - Problems while trying to write the record.

close

public void close()
Closes the writer and all the resource being used by this writer. This includes the output stream passed to construct the writer.

Specified by:
close in class FileWriter