1 4 5 9 10 package org.openlaszlo.cm; 11 import org.openlaszlo.compiler.*; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.FileNotFoundException ; 16 import java.io.FileOutputStream ; 17 import java.io.IOException ; 18 import java.io.ObjectInputStream ; 19 import java.io.ObjectOutputStream ; 20 import java.io.Serializable ; 21 22 import org.apache.log4j.*; 23 24 30 public class CachedInfo implements Serializable { 31 32 private final static Logger mLogger = Logger.getLogger(CachedInfo.class); 33 private final DependencyTracker mTracker; 34 private final Canvas mCanvas; 35 private final String mEncoding; 36 37 42 public CachedInfo(DependencyTracker tracker, Canvas canvas, String encoding) { 43 mTracker = tracker; 44 mCanvas = canvas; 45 mEncoding = encoding; 46 } 47 48 51 public static CachedInfo readFrom(File file) 52 throws CompilationError 53 { 54 CachedInfo info = null; 55 56 try { 57 FileInputStream istream = new FileInputStream (file); 58 try { 59 ObjectInputStream p = new ObjectInputStream (istream); 60 return (CachedInfo) p.readObject(); 61 } finally { 62 istream.close(); 63 } 64 } catch (java.io.InvalidClassException ioe) { 65 } catch (FileNotFoundException ioe) { 66 } catch (IOException ioe) { 67 CompilationError e = new CompilationError(ioe); 68 e.initPathname(file.getPath()); 69 mLogger.error(e.getMessage()); 70 throw e; 71 } catch (ClassNotFoundException cnfe) { 72 } 73 return new CachedInfo(null, null, null); 74 } 75 76 80 void writeTo(File file) throws IOException { 81 mLogger.debug("writeTo " + file.getAbsolutePath()); 82 File dir = file.getParentFile(); 83 if (dir != null) { 84 dir.mkdirs(); 85 } 86 file.createNewFile(); 87 FileOutputStream ostream = new FileOutputStream (file); 88 ObjectOutputStream p = new ObjectOutputStream (ostream); 89 p.writeObject(this); 90 p.flush(); 91 ostream.close(); 92 } 93 94 public Canvas getCanvas() { 95 mLogger.debug("Getting canvas with size " + mCanvas.getWidth() + 96 " by " + mCanvas.getHeight()); 97 return mCanvas; 98 } 99 100 public String getEncoding() { 101 return mEncoding; 102 } 103 104 105 public DependencyTracker getDependencyTracker() { 106 return mTracker; 107 } 108 } 109 | Popular Tags |