Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20669
Added Files:
FileWriter.java
Log Message:
no message
--- NEW FILE: FileWriter.java ---
/*
* FileWriter.java
*
* Created on June 6, 2006, 8:59 AM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package org.jmonks.batchserver.io;
import java.io.File;
import org.jmonks.batchserver.io.flat.FixedWidthFlatFileWriter;
/**
*
* @author Suresh Pragada
*/
public abstract class FileWriter
{
public abstract WriterRecord createWriterRecord(RecordType recordType);
public abstract void writerRecord(WriterRecord record);
public abstract void close();
public static FileWriter getFileWriter(String absoluteFilePath,String absoluteFileSpecPath)
{
if(absoluteFilePath==null)
throw new IllegalArgumentException("Absolute file path to create the writer cannot be null.");
else if((new File(absoluteFilePath)).exists())
throw new IllegalArgumentException("Absolute file path to create the writer should not exist. Given absolute file path = " + absoluteFilePath);
else if ((new File(absoluteFilePath)).isDirectory())
throw new IllegalArgumentException("Absolute file path to create the writer should not be directory. Given absolute file path = " + absoluteFilePath);
if(absoluteFileSpecPath==null)
throw new IllegalArgumentException("Absolute file path to read the file spec cannot be null.");
else if(!(new File(absoluteFileSpecPath).exists() && new File(absoluteFileSpecPath).isFile()))
throw new IllegalArgumentException("Absolute file path to read the file spec should exist and should be a file. Given absolute file spec path = " + absoluteFileSpecPath);
FileSpec fileSpec=FileSpec.createFileSpec(absoluteFileSpecPath);
if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE)
{
return new FixedWidthFlatFileWriter(absoluteFilePath,fileSpec);
}
else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE)
{
return null; // Create Demlited Flat file reader.
}
else if(fileSpec.getFileType()==FileType.XML_FILE)
{
return null;//new XMLFileWriter(absoluteFilePath,fileSpec);
}
else
{
throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString());
}
}
}
|