KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > util > FileResource


1 package org.sapia.soto.util;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7
8 import java.net.MalformedURLException JavaDoc;
9
10
11 /**
12  * Implements a <code>Resource</code> over a <code>File</code>
13  *
14  * @see org.sapia.soto.util.Resource
15  * @see java.io.File
16  *
17  * @author Yanick Duchesne
18  *
19  * <dl>
20  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
21  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
22  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
23  * </dl>
24  */

25 public class FileResource implements Resource {
26   private File JavaDoc _file;
27
28   public FileResource(File JavaDoc f) {
29     _file = f;
30   }
31
32   /**
33    * @see org.sapia.soto.util.Resource#getURI()
34    */

35   public String JavaDoc getURI() {
36     try {
37       return _file.toURL().toExternalForm();
38     } catch (MalformedURLException JavaDoc e) {
39       throw new IllegalStateException JavaDoc("Could not create URL from resource: " +
40         _file.getAbsolutePath() + "; caught: " + e.getClass().getName() +
41         " - " + e.getMessage());
42     }
43   }
44
45   /**
46    * @see org.sapia.soto.util.Resource#getInputStream()
47    */

48   public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
49     return new FileInputStream JavaDoc(_file);
50   }
51
52   /**
53    * @see org.sapia.soto.util.Resource#lastModified()
54    */

55   public long lastModified() {
56     return _file.lastModified();
57   }
58
59   public String JavaDoc toString() {
60     return _file.getAbsolutePath();
61   }
62 }
63
Popular Tags