[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io FileReader.java, 1.12, 1.13 FileSpec.ja
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-06-13 22:10:00
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28202 Modified Files: FileReader.java FileSpec.java FileWriter.java package.html RecordType.java Log Message: no message Index: FileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FileWriter.java 13 Jun 2006 04:01:36 -0000 1.7 --- FileWriter.java 13 Jun 2006 22:09:54 -0000 1.8 *************** *** 12,15 **** --- 12,16 ---- import java.io.InputStream; import java.io.OutputStream; + import java.io.Writer; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.flat.DelimitedFlatFileWriter; *************** *** 129,131 **** --- 130,193 ---- throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); } + + /** + * <p> + * Factory method to get the file writer. This method returns the appropriate file writer + * based on the file type specified in the file spec. + * </p> + * + * @param writer Writer to write the records. + * @param fileSpecInputStream Input stream to read the file spec. + * + * @return Returns the appropriate writer. + * + * @throws IllegalArgumentException If the given file output stream or file spec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileWriter getFileWriter(Writer writer,InputStream fileSpecInputStream) + { + logger.trace("Entering getFileReader"); + if(writer==null) + throw new IllegalArgumentException("Writer to write the records cannot be null."); + if(fileSpecInputStream==null) + throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); + + FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); + return FileWriter.getFileWriter(writer, fileSpec); + } + + /** + * <p> + * Factory method to get the file writer. This method returns the appropriate file writer + * based on the file type specified in the file spec. + * </p> + * + * @param writer Writer to write the records. + * @param fileSpec File spec to be used to create the writer. + * + * @return Returns the appropriate writer. + * + * @throws IllegalArgumentException If the given file output stream or file spec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileWriter getFileWriter(Writer writer, FileSpec fileSpec) + { + logger.trace("Entering getFileReader"); + if(writer==null) + throw new IllegalArgumentException("Writer to write the records cannot be null."); + if(fileSpec==null) + throw new IllegalArgumentException("File spec to create the writer cannot be null."); + + logger.debug("Given file spec = " + fileSpec.toString()); + if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) + return new FixedWidthFlatFileWriter(writer,fileSpec); + else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) + return new DelimitedFlatFileWriter(writer, fileSpec); + else if(fileSpec.getFileType()==FileType.XML_FILE) + return new XMLFileWriter(writer,fileSpec); + else + throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); + } } Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/package.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** package.html 13 Jun 2006 04:01:36 -0000 1.2 --- package.html 13 Jun 2006 22:09:54 -0000 1.3 *************** *** 5,9 **** </head> <body> ! Explain the usage of IO API. </body> </html> --- 5,17 ---- </head> <body> ! Defines API to be used by clients to read records from the files and writer ! records to the file. ! <p> ! This package provides the API for the clients to work with the files easily ! irrespective of the file format. This API is based on the analogy that all the ! files have some data in the form of records and each record consists set of ! fields and the structure of these files, records and fields can be defined or ! configured using xml file. API parses or generates the records ! </p> </body> </html> Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** FileSpec.java 10 Jun 2006 17:50:24 -0000 1.10 --- FileSpec.java 13 Jun 2006 22:09:54 -0000 1.11 *************** *** 118,123 **** --- 118,128 ---- /** + * <p> * Gets all the record spec's in this file spec as a list. * + * TODO :: There is chance that client might misuse this list. Based on the + * performance create a new list and return it. + * </p> + * * @return Returns record spec's as a list. */ Index: RecordType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordType.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RecordType.java 10 Jun 2006 17:50:24 -0000 1.6 --- RecordType.java 13 Jun 2006 22:09:54 -0000 1.7 *************** *** 44,52 **** if(type!=null) { ! if("HEADER".equalsIgnoreCase(type) || "DETAIL".equalsIgnoreCase(type) || "TRAILOR".equalsIgnoreCase(type) ! || "BLOCK-START".equalsIgnoreCase(type) || "BLOCK-END".equalsIgnoreCase(type)) ! throw new IllegalArgumentException("Record type value " + type + " is in use."); ! else ! this.type=type; } else --- 44,48 ---- if(type!=null) { ! this.type=type; } else *************** *** 67,79 **** public static RecordType toRecordType(String recordType) { ! if(RecordType.HEADER.equals(recordType)) return RecordType.HEADER; ! else if(RecordType.DETAIL.equals(recordType)) return RecordType.DETAIL; ! else if(RecordType.TRAILOR.equals(recordType)) return RecordType.TRAILOR; ! else if(RecordType.BLOCK_START.equals(recordType)) return RecordType.BLOCK_START; ! else if(RecordType.BLOCK_END.equals(recordType)) return RecordType.BLOCK_END; else --- 63,75 ---- public static RecordType toRecordType(String recordType) { ! if(RecordType.HEADER.toString().equalsIgnoreCase(recordType)) return RecordType.HEADER; ! else if(RecordType.DETAIL.toString().equalsIgnoreCase(recordType)) return RecordType.DETAIL; ! else if(RecordType.TRAILOR.toString().equalsIgnoreCase(recordType)) return RecordType.TRAILOR; ! else if(RecordType.BLOCK_START.toString().equalsIgnoreCase(recordType)) return RecordType.BLOCK_START; ! else if(RecordType.BLOCK_END.toString().equalsIgnoreCase(recordType)) return RecordType.BLOCK_END; else Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** FileReader.java 13 Jun 2006 04:01:35 -0000 1.12 --- FileReader.java 13 Jun 2006 22:09:53 -0000 1.13 *************** *** 11,14 **** --- 11,15 ---- package org.jmonks.batchserver.io; import java.io.InputStream; + import java.io.Reader; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.flat.DelimitedFlatFileReader; *************** *** 125,127 **** --- 126,189 ---- throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); } + + /** + * <p> + * Factory method to get the file reader. This method returns the appropriate file reader + * based on the file type specified in the file spec. + * </p> + * + * @param reader Reader to read the data file. + * @param fileSpecInputStream Input stream to read the file spec. + * + * @return Returns the appropriate reader. + * + * @throws IllegalArgumentException If the given fileInputStream or fileSpecInputStream is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileReader getFileReader(Reader reader,InputStream fileSpecInputStream) + { + logger.trace("Entering getFileReader"); + if(reader==null) + throw new IllegalArgumentException("Reader to read the data file cannot be null."); + if(fileSpecInputStream==null) + throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); + + FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); + return FileReader.getFileReader(reader, fileSpec); + } + /** + * <p> + * Factory method to get the file reader. This method returns the appropriate file reader + * based on the file type specified in the file spec. + * </p> + * + * @param reader Reader to read the data file. + * @param fileSpec File spec to create the file reader. + * + * @return Returns the appropriate reader. + * + * @throws IllegalArgumentException If the given fileInputStream or fileSpec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileReader getFileReader(Reader reader, FileSpec fileSpec) + { + logger.trace("Entering getFileReader"); + if(reader==null) + throw new IllegalArgumentException("Reader to read the data file cannot be null."); + if(fileSpec==null) + throw new IllegalArgumentException("File spec cannot be null to create the file reader."); + + logger.debug("Given file spec = " + fileSpec.toString()); + if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) + return new FixedWidthFlatFileReader(reader,fileSpec); + else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) + return new DelimitedFlatFileReader(reader,fileSpec); + else if(fileSpec.getFileType()==FileType.XML_FILE) + return new XMLFileReader(reader,fileSpec); + else + throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); + } + } |