[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io/flat package.html, 1.2, 1.3
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-06-15 03:35:55
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv715/flat Modified Files: package.html Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/package.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** package.html 14 Jun 2006 21:01:51 -0000 1.2 --- package.html 15 Jun 2006 03:35:52 -0000 1.3 *************** *** 10,14 **** 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. </p> --- 10,15 ---- 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. </p> *************** *** 18,29 **** is starts with some value to identify the record and each record consists of set of of fields where each field starts at one position and ends at one position. ! </p> <p> <h3>Delimited Flat File Implementation</h3> Delimited flat files consists of set of records of same type where all the records consists of same number of fields and each field is are delimited by a special value ! in the record. </p> --- 19,154 ---- is starts with some value to identify the record and each record consists of set of of fields where each field starts at one position and ends at one position. ! <h5>Defining the file spec for fixed width flat files</h5> ! File spec which descibes the fixed width flat file expects the <code>file-type</code> ! attribute value should be "fixed-width-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! </file-spec> ! </pre> ! There could be multiple record specs exists in a file spec. Along with the ! record-type attribute, it requires an additional attribute <code>starts-with</code> ! which tells the value that the record starts with. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5"> ! </record-spec> ! </file-spec> ! </pre> ! 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 <code>start-pos</code> which ! tells the starting position of the field in the record and <code>end-pos</code> which ! tells the ending position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5"> ! <field-spec field-name="field-name1" start-pos="12" end-pos="23"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from fixed width flat files</h5> ! Reading the records from the fixed width flat files is fairly simple. ! <pre style="color:green"> ! <i> ! 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(); ! </i> ! </pre> ! <h5>Writing the records into fixed width flat files</h5> ! Writing the records into fixed width flat files is fairly simple. ! <pre style="color:green"> ! <i> ! 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(); ! </i> ! </pre> </p> + <p> <h3>Delimited Flat File Implementation</h3> Delimited flat files consists of set of records of same type where all the records consists of same number of fields and each field is are delimited by a special value ! in the record. ! <h5>Defining the file spec for delimited flat files</h5> ! File spec which descibes the delimited flat file expects the <code>file-type</code> ! attribute value should be "delimited-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="delimited-flat"> ! </file-spec> ! </pre> ! 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 an additional attribute <code>delimiter</code> ! which tells the value that delimits the fields in the record. ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|"> ! </record-spec> ! </file-spec> ! </pre> ! 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 <code>index</code> which ! tells the position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|"> ! <field-spec field-name="field-name1" index="3"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from delimited flat files</h5> ! Reading the records from the delimited flat files is fairly simple. ! <pre style="color:green"> ! <i> ! 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(); ! </i> ! </pre> ! <h5>Writing the records into delimited flat files</h5> ! Writing the records into delimited flat files is fairly simple. ! <pre style="color:green"> ! <i> ! 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(); ! </i> ! </pre> </p> |