1 package polyglot.frontend; 2 3 import java.io.*; 4 import java.util.*; 5 6 import polyglot.util.InternalCompilerError; 7 8 9 public class FileSource extends Source 10 { 11 protected final File file; 12 protected FileReader reader; 13 14 public FileSource(File file) throws IOException { 15 this(file, false); 16 } 17 18 public FileSource(File file, boolean userSpecified) throws IOException { 19 super(file.getName(), userSpecified); 20 this.file = file; 21 22 if (! file.exists()) { 23 throw new FileNotFoundException(file.getName()); 24 } 25 26 path = file.getPath(); 27 lastModified = new Date(file.lastModified()); 28 } 29 30 public boolean equals(Object o) { 31 if (o instanceof FileSource) { 32 FileSource s = (FileSource) o; 33 return file.equals(s.file); 34 } 35 36 return false; 37 } 38 39 public int hashCode() { 40 return file.getPath().hashCode(); 41 } 42 43 44 public Reader open() throws IOException { 45 if (reader == null) { 46 reader = new FileReader(file); 47 } 48 49 return reader; 50 } 51 52 53 public void close() throws IOException { 54 if (reader != null) { 55 reader.close(); 56 reader = null; 57 } 58 } 59 60 public String toString() { 61 return file.getPath(); 62 } 63 } 64 | Popular Tags |