[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io FileReader.java, 1.9, 1.10 FileSpec.jav
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-06-09 21:36:44
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3769 Modified Files: FileReader.java FileSpec.java FileWriter.java Log Message: no message Index: FileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FileWriter.java 8 Jun 2006 22:21:15 -0000 1.4 --- FileWriter.java 9 Jun 2006 21:36:34 -0000 1.5 *************** *** 10,15 **** package org.jmonks.batchserver.io; ! ! import java.io.File; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.flat.FixedWidthFlatFileWriter; --- 10,15 ---- package org.jmonks.batchserver.io; ! import java.io.InputStream; ! import java.io.OutputStream; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.flat.FixedWidthFlatFileWriter; *************** *** 74,79 **** * </p> * ! * @param filePath Absolute path to create the data file. Path should not be directory and should not exist on the file system. ! * @param fileSpecPath Absolute path to the file contains the file spec. * * @return Returns the appropriate writer. --- 74,79 ---- * </p> * ! * @param outputStream Output stream to write the records. ! * @param fileSpecInputStream Input stream to read the file spec. * * @return Returns the appropriate writer. *************** *** 84,110 **** * exist in FileType class. */ ! public static FileWriter getFileWriter(String filePath,String fileSpecPath) { ! logger.trace("Entering getFileReader file path = " + filePath + " File spec path = " + fileSpecPath); ! if(filePath==null) ! throw new IllegalArgumentException("Absolute file path to create the writer cannot be null."); ! else if((new File(filePath)).exists()) ! throw new IllegalArgumentException("Absolute file path to create the writer should not exist. Given absolute file path = " + filePath); ! else if ((new File(filePath)).isDirectory()) ! throw new IllegalArgumentException("Absolute file path to create the writer should not be directory. Given absolute file path = " + filePath); ! if(fileSpecPath==null) ! throw new IllegalArgumentException("Absolute file path to read the file spec cannot be null."); ! else if(!(new File(fileSpecPath).exists() && new File(fileSpecPath).isFile())) ! throw new IllegalArgumentException("Absolute file path to read the file spec should exist and should be a file. Given absolute file spec path = " + fileSpecPath); ! FileSpec fileSpec=FileSpec.createFileSpec(fileSpecPath); logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! return new FixedWidthFlatFileWriter(filePath,fileSpec); else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) return null; // Create Demlited Flat file reader. else if(fileSpec.getFileType()==FileType.XML_FILE) ! return new XMLFileWriter(filePath,fileSpec); else throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); --- 84,105 ---- * exist in FileType class. */ ! public static FileWriter getFileWriter(OutputStream outputStream,InputStream fileSpecInputStream) { ! logger.trace("Entering getFileReader"); ! if(outputStream==null) ! throw new IllegalArgumentException("Output stream 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); logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! return new FixedWidthFlatFileWriter(outputStream,fileSpec); else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) return null; // Create Demlited Flat file reader. else if(fileSpec.getFileType()==FileType.XML_FILE) ! return new XMLFileWriter(outputStream,fileSpec); else throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** FileReader.java 8 Jun 2006 22:21:15 -0000 1.9 --- FileReader.java 9 Jun 2006 21:36:34 -0000 1.10 *************** *** 12,15 **** --- 12,16 ---- import java.io.File; + import java.io.InputStream; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.xml.XMLFileReader; *************** *** 72,77 **** * </p> * ! * @param filePath Absolute path to read the data file. ! * @param fileSpecPath Absolute path to the file contains the file spec. * * @return Returns the appropriate reader. --- 73,78 ---- * </p> * ! * @param fileInputStream Input stream to read the data file. ! * @param fileSpecInputStream Input stream to read the file spec. * * @return Returns the appropriate reader. *************** *** 82,106 **** * exist in FileType class. */ ! public static FileReader getFileReader(String filePath,String fileSpecPath) { ! logger.trace("Entering getFileReader file path = " + filePath + " File spec path = " + fileSpecPath); ! if(filePath==null) ! throw new IllegalArgumentException("Absolute file path to create the reader cannot be null."); ! else if(!(new File(filePath).exists() && new File(filePath).isFile())) ! throw new IllegalArgumentException("Absolute file path to create the reader should exist and should be a file. Given absolute file path = " + filePath); ! if(fileSpecPath==null) ! throw new IllegalArgumentException("Absolute file path to read the file spec cannot be null."); ! else if(!(new File(fileSpecPath).exists() && new File(fileSpecPath).isFile())) ! throw new IllegalArgumentException("Absolute file path to read the file spec should exist and should be a file. Given absolute file spec path = " + fileSpecPath); ! FileSpec fileSpec=FileSpec.createFileSpec(fileSpecPath); logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! return new FixedWidthFlatFileReader(filePath,fileSpec); else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) return null; // Create Demlited Flat file reader. else if(fileSpec.getFileType()==FileType.XML_FILE) ! return new XMLFileReader(filePath,fileSpec); else throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); --- 83,104 ---- * exist in FileType class. */ ! public static FileReader getFileReader(InputStream fileInputStream,InputStream fileSpecInputStream) { ! logger.trace("Entering getFileReader"); ! ! if(fileInputStream==null) ! throw new IllegalArgumentException("Input stream 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); logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! return new FixedWidthFlatFileReader(fileInputStream,fileSpec); else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) return null; // Create Demlited Flat file reader. else if(fileSpec.getFileType()==FileType.XML_FILE) ! return new XMLFileReader(fileInputStream,fileSpec); else throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FileSpec.java 8 Jun 2006 22:21:15 -0000 1.8 --- FileSpec.java 9 Jun 2006 21:36:34 -0000 1.9 *************** *** 61,68 **** { /** - * Holds the path of the file contains the spec of any file to read/write. - */ - protected String fileSpecPath=null; - /** * Holds the type of the file this spec is representing. */ --- 61,64 ---- *************** *** 90,96 **** * @param fileType Type of the file this spec is representing. */ ! protected FileSpec(String fileSpecPath,FileType fileType) { - this.fileSpecPath=fileSpecPath; this.fileType=fileType; recordSpecMap=new HashMap(); --- 86,91 ---- * @param fileType Type of the file this spec is representing. */ ! protected FileSpec(FileType fileType) { this.fileType=fileType; recordSpecMap=new HashMap(); *************** *** 174,178 **** * file spec object. * </p> ! * @param fileSpecPath Absolute path to the file contains spec. * * @return Returns the file spec object. --- 169,173 ---- * file spec object. * </p> ! * @param fileSpecInputStream Input stream represents the file spec. * * @return Returns the file spec object. *************** *** 182,194 **** * or given file cannot be found or cannot parse the file. */ ! public static FileSpec createFileSpec(String fileSpecPath) { ! logger.trace("Entering createFileSpec = " + fileSpecPath); try { ! InputStream fileSpecStream=new FileInputStream(new File(fileSpecPath)); DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); ! Document document=documentBuilder.parse(fileSpecStream); Element fileSpecElement=document.getDocumentElement(); --- 177,190 ---- * or given file cannot be found or cannot parse the file. */ ! public static FileSpec createFileSpec(InputStream fileSpecInputStream) { ! logger.trace("Entering createFileSpec"); try { ! if(fileSpecInputStream==null) ! throw new IllegalArgumentException("File spec input stream to read the file spec cannot be null."); DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); ! Document document=documentBuilder.parse(fileSpecInputStream); Element fileSpecElement=document.getDocumentElement(); *************** *** 199,218 **** FileType fileType=FileType.toFileType(configuredFileType); if(fileType==FileType.FIXED_WIDTH_FLAT_FILE) ! return FixedWidthFlatFileFileSpec.createFixedWidthFlatFileFileSpec(fileSpecPath,fileSpecElement); else if(fileType==FileType.DELIMITED_FLAT_FILE) return null; //DelimitedFlatFileFileSpec.createDelimitedFlatFileFileSpec(fileSpecPath,fileSpecElement); else if(fileType==FileType.XML_FILE) ! return XMLFileSpec.createXMLFileSpec(fileSpecPath,fileSpecElement); else ! throw new FileSpecException("Configured file type " + fileType + " in the file spec is not recognizable. File spec location = " + fileSpecPath); } else ! throw new FileSpecException("File spec root element doesnt match the expected " + FileSpec.FILE_SPEC_TAG_NAME + " value in the file spec located at = " + fileSpecPath); ! } ! catch(FileNotFoundException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Cannot find the file in the given path = " + fileSpecPath,exception); ! throw new FileSpecException("Cannot find the file contains the spec in given location = ." + fileSpecPath + " Message = " + exception.getMessage()); } catch(ParserConfigurationException exception) --- 195,208 ---- FileType fileType=FileType.toFileType(configuredFileType); if(fileType==FileType.FIXED_WIDTH_FLAT_FILE) ! return FixedWidthFlatFileFileSpec.createFixedWidthFlatFileFileSpec(fileSpecElement); else if(fileType==FileType.DELIMITED_FLAT_FILE) return null; //DelimitedFlatFileFileSpec.createDelimitedFlatFileFileSpec(fileSpecPath,fileSpecElement); else if(fileType==FileType.XML_FILE) ! return XMLFileSpec.createXMLFileSpec(fileSpecElement); else ! throw new FileSpecException("Configured file type " + fileType + " in the file spec is not recognizable."); } else ! throw new FileSpecException("File spec root element doesnt match the expected " + FileSpec.FILE_SPEC_TAG_NAME + " value in the file spec obtained from the given stream."); } catch(ParserConfigurationException exception) *************** *** 225,236 **** { exception.printStackTrace(); ! logger.fatal("Parsing exception while parsing the file spec = " + fileSpecPath,exception); ! throw new FileSpecException("Parsing exception while parsing the file spec in given location = " + fileSpecPath + " Message = " + exception.getMessage()); } catch(IOException exception) { exception.printStackTrace(); ! logger.fatal("IO exception while parsing the file spec = " + fileSpecPath,exception); ! throw new FileSpecException("IO exception while parsing the file spec in given location=" + fileSpecPath + " Message = " + exception.getMessage()); } } --- 215,226 ---- { exception.printStackTrace(); ! logger.fatal("Parsing exception while parsing the given inputstream.",exception); ! throw new FileSpecException("Parsing exception while parsing the file spec in given input stream. Message = " + exception.getMessage()); } catch(IOException exception) { exception.printStackTrace(); ! logger.fatal("IO exception while parsing the given input stream to create the file spec.",exception); ! throw new FileSpecException("IO exception while parsing the given input stream to create the file spec. Message = " + exception.getMessage()); } } |