Main Page   Class Hierarchy   Compound List   File List   Compound Members  

MEAPFile.java

00001 /*
00002  *  Copyright 2006 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
00021  */
00022 
00023 package com.meapsoft;
00024 
00025 import java.io.BufferedWriter;
00026 import java.io.FileWriter;
00027 import java.io.IOException;
00028 import java.io.Serializable;
00029 import java.io.StringWriter;
00030 import java.io.Writer;
00031 
00038 public abstract class MEAPFile implements Serializable
00039 {
00040     //protected String filename;
00041     public String filename;
00042     public boolean haveReadFile = false;
00043     public boolean haveWrittenFile = false;
00044 
00048     public abstract void readFile() throws IOException, ParserException;
00049 
00053     protected abstract void write(Writer w) throws IOException;
00054 
00058     public void writeFile() throws IOException
00059     {
00060         writeFile(filename);
00061     }
00062 
00066     public void writeFile(String fn) throws IOException
00067     {
00068         writeFile(fn, false);
00069     }
00070 
00076     public void writeFile(String fn, boolean append) throws IOException
00077     {
00078         if(fn == null)
00079             fn = filename;
00080 
00081         // only append if we are outputting to a different file
00082         BufferedWriter out = new BufferedWriter(new FileWriter(fn, append));
00083         write(out);
00084         out.close();
00085 
00086         haveWrittenFile = true;
00087     }
00088 
00093     public String toString()
00094     {
00095         StringWriter s = new StringWriter();
00096 
00097         try { write(s); }
00098         // this can't happen on a StringWriter, but we must appease Java
00099         catch(IOException e) {;}  
00100 
00101         return s.toString();
00102     }
00103 }

Generated on Thu May 11 15:04:10 2006 for MEAPsoft by doxygen1.2.18