Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package org.jicengine.io; 2 3 import java.io.*; 4 5 15 16 public class FileResource extends AbstractResource implements UrlReadable { 17 18 private File file; 19 20 public FileResource(File file) 21 { 22 super(file.getAbsolutePath()); 23 this.file = file; 24 } 25 26 public FileResource(String filePath) 27 { 28 this(new File(filePath)); 29 } 30 31 public File getFile() 32 { 33 return this.file; 34 } 35 36 public File toFile() 37 { 38 return getFile(); 39 } 40 41 public java.net.URL getUrl() throws IOException 42 { 43 try { 44 return getFile().toURL(); 45 } catch (java.net.MalformedURLException e){ 46 throw new IOException("Failed to transform FileResource to URL: " + e); 47 } 48 } 49 50 public boolean isAvailable() 51 { 52 return getFile().canRead(); 53 } 54 55 public InputStream getInputStream() throws java.io.IOException  56 { 57 return new FileInputStream(getFile()); 58 } 59 60 public Resource getResource(String relativePath) 61 { 62 File baseFile = getFile(); 63 if( !baseFile.isDirectory() ){ 64 baseFile = baseFile.getParentFile(); 65 } 66 return new FileResource(new File(baseFile, relativePath)); 67 } 68 } 69
| Popular Tags
|