|
|||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Class Summary | |
DelimitedFlatFileFieldSpec |
DelimitedFlatFileFieldSpec represents field-spec element in the record spec
element belongs to the delimited flat file type. |
DelimitedFlatFileFileSpec | DelimitedFlatFileFileSpec represents the file spec defines the flat file where all the fields in the records delimited with a particular character or value. |
DelimitedFlatFileReader | DelimitedFlatFileReader reads the specified delimited flat file according to the given file spec and returns the recrods on the needed basis. |
DelimitedFlatFileRecordSpec | DelimitedFlatFileRecordSpec represents record-spec element in the file spec belongs to the delimited flat file type. |
DelimitedFlatFileWriter | DelimitedFlatFileWriter writes the file according to the given file spec with the data submitted in the form of WriterRecord's. |
FixedWidthFlatFileFieldSpec |
FixedWidthFlatFileFieldSpec represents field-spec element in the record spec
belongs to the fixed width flat file type. |
FixedWidthFlatFileFileSpec | FixedWidthFlatFileFileSpec represents the file spec defines the flat file where each different kind of record starts with a particular value and the fields in each record will have start and end position. |
FixedWidthFlatFileReader | FixedWidthFlatFileReader reads the specified fixed width flat file according to the given file spec and returns the recrods on the needed basis. |
FixedWidthFlatFileRecordSpec | FixedWidthFlatFileRecordSpec represents record-spec element in the file spec belongs to the fixed width flat file type. |
FixedWidthFlatFileWriter | FixedWidthFlatFileWriter writes the file according to the given file spec with the data submitted in the form of WriterRecord's. |
FlatFileReader | FlatFileReader reads the specified fixed width flat file according to the given file spec and returns the recrods on the needed basis. |
FlatFileWriter | FlatFileWriter writes/generates the file according to the given file spec with the data submitted in the form of WriterRecord's. |
Flat file implementation for the IO API.
Flat files are the common type of files being used by the enterprises to exchange the data. This package provides the implementation to read and write two flat file formats fixed width and delimited flat files. Implementation assumes that each line in a flat file corresponds to a record and there is a way to identify each record and each field in that record.
file-type
attribute value should be "fixed-width-flat". It doesnt require any additional
attributes along with the file-type
attribute.
<file-spec file-type="fixed-width-flat"> </file-spec>There could be multiple record specs exists in a file spec. Along with the
record-type
attribute, it requires two additional attributes
starts-with
which tells the value that the record should starts with
and record-length
which tells the lenght of the record.
<file-spec file-type="fixed-width-flat"> <record-spec record-type="DETAIL" starts-with="5" record-length="42"> </record-spec> </file-spec>There could be multiple field specs exists in a single record spec. Field spec requires few additional attributes along with the field-name attribute to identify or extract the field from the record. These attributes are
start-pos
which
tells the starting position of the field in the record and end-pos
which
tells the ending position of the field in the record. Starting index in a record starts with "1".
<file-spec file-type="fixed-width-flat"> <record-spec record-type="DETAIL" starts-with="5" record-length="42"> <field-spec field-name="field-name1" start-pos="12" end-pos="23"/> </record-spec> </file-spec>
InputStream fileSpecInputStream= // Get the input stream for the XML file contains the file structure. InputStream fileInputStream= // Get the input stream of the file to be read. FileReader reader=FileReader.getFileReader(fileInputStream,fileSpecInputStream); ReaderRecord record=null; while((record=reader.getNextRecord())!=null) { if(record.getRecordType().equals(RecordType.DETAIL)) { String fieldValue1=record.readField("field-name1"); // Read the rest of the field and does the processing. } } reader.close();
InputStream fileSpecInputStream= // Get the input stream for the XML file contains the file structure. OutputStream fileOutputStream= // Get the output stream of the file to be written/generated. FileWriter writer=FileWriter.getFileWriter(fileOutputStream,fileSpecInputStream); WriterRecord record=writer.createWriterRecord(RecordType.DETAIL); record.writeField("field-name1","field-value1"); // Write all the other field values into the writer record. writer.writeRecord(record); writer.close();
file-type
attribute value should be "delimited-flat". It doesnt require any additional
attributes along with the file-type
attribute.
<file-spec file-type="delimited-flat"> </file-spec>Since all the records in delimited flat file of the same type, it allows only one record spec should exists in the file spec. Along with the record-type attribute, it requires two additional attributes
delimiter
and field-count
. Attributes delimiter
tells the value
that delimites fields among the record and attribute field-count
tells the number of fields can exists in the record.
<file-spec file-type="delimited-flat"> <record-spec record-type="DETAIL" delimiter="|" field-count="4"> </record-spec> </file-spec>There could be multiple field specs exists in a record spec. Field spec requires one additional attributes along with the field-name attribute to identify or extract the field from the record. This attribute is
index
which
tells the position of the field in the record. Starting index in a record starts with "1".
<file-spec file-type="delimited-flat"> <record-spec record-type="DETAIL" delimiter="|" field-count="4"> <field-spec field-name="field-name1" index="3"/> </record-spec> </file-spec>
InputStream fileSpecInputStream= // Get the input stream for the XML file contains the file structure. InputStream fileInputStream= // Get the input stream of the file to be read. FileReader reader=FileReader.getFileReader(fileInputStream,fileSpecInputStream); ReaderRecord record=null; while((record=reader.getNextRecord())!=null) { if(record.getRecordType().equals(RecordType.DETAIL)) { String fieldValue1=record.readField("field-name1"); // Read the rest of the field and does the processing. } } reader.close();
InputStream fileSpecInputStream= // Get the input stream for the XML file contains the file structure. OutputStream fileOutputStream= // Get the output stream of the file to be written/generated. FileWriter writer=FileWriter.getFileWriter(fileOutputStream,fileSpecInputStream); WriterRecord record=writer.createWriterRecord(RecordType.DETAIL); record.writeField("field-name1","field-value1"); // Write all the other field values into the writer record. writer.writeRecord(record); writer.close();
|
|||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |