1 package org.sapia.soto.util; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.IOException ; 6 import java.io.InputStream ; 7 8 import java.net.MalformedURLException ; 9 10 11 25 public class FileResource implements Resource { 26 private File _file; 27 28 public FileResource(File f) { 29 _file = f; 30 } 31 32 35 public String getURI() { 36 try { 37 return _file.toURL().toExternalForm(); 38 } catch (MalformedURLException e) { 39 throw new IllegalStateException ("Could not create URL from resource: " + 40 _file.getAbsolutePath() + "; caught: " + e.getClass().getName() + 41 " - " + e.getMessage()); 42 } 43 } 44 45 48 public InputStream getInputStream() throws IOException { 49 return new FileInputStream (_file); 50 } 51 52 55 public long lastModified() { 56 return _file.lastModified(); 57 } 58 59 public String toString() { 60 return _file.getAbsolutePath(); 61 } 62 } 63 | Popular Tags |