Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

MEAPFile.java

00001 /*
00002  *  Copyright 2006-2007 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     public String filename;
00041     
00042     // have we read this file in yet?
00043     public boolean haveReadFile = false;
00044 
00045     // have we written this file yet?
00046     public boolean haveWrittenFile = false;
00047         
00051     public abstract void readFile() throws IOException, ParserException;
00052 
00056     protected abstract void write(Writer w) throws IOException;
00057 
00061     public void writeFile() throws IOException
00062     {
00063         writeFile(filename);
00064     }
00065 
00069     public void writeFile(String fn) throws IOException
00070     {
00071         writeFile(fn, false);
00072     }
00073 
00079     public void writeFile(String fn, boolean append) throws IOException
00080     {
00081         if(fn == null)
00082             fn = filename;
00083 
00084         // only append if we are outputting to a different file
00085         BufferedWriter out = new BufferedWriter(new FileWriter(fn, append));
00086         write(out);
00087         out.close();
00088 
00089         haveWrittenFile = true;
00090     }
00091 
00096     public String toString()
00097     {
00098         StringWriter s = new StringWriter();
00099 
00100         try { write(s); }
00101         // this can't happen on a StringWriter, but we must appease Java
00102         catch(IOException e) {;}  
00103 
00104         return s.toString();
00105     }
00106 }

Generated on Tue Feb 6 19:02:26 2007 for MEAPsoft by doxygen1.2.18