1 8 package org.apache.avalon.excalibur.vfs; 9 10 import java.io.File ; 11 import java.io.FileInputStream ; 12 import java.io.InputStream ; 13 14 19 public final class DirectoryVFileAccessor 20 implements VFileAccessor 21 { 22 28 public long getSize( final VFile file, final Object resource ) 29 { 30 try 31 { 32 final File realFile = getFile( file, resource ); 33 return realFile.length(); 34 } 35 catch( final Exception e ) 36 { 37 return -1; 38 } 39 } 40 41 48 public InputStream getInputStream( final VFile file, final Object resource ) 49 { 50 try 51 { 52 final File realFile = getFile( file, resource ); 53 return new FileInputStream ( realFile ); 54 } 55 catch( final Exception e ) 56 { 57 return null; 58 } 59 } 60 61 68 private File getFile( final VFile file, final Object resource ) 69 { 70 final File baseFile = (File )resource; 71 final String name = file.toString().substring( 1 ).replace( '/', File.separatorChar ); 72 return new File ( baseFile, name ); 73 } 74 } 75 | Popular Tags |