001 package railo.commons.io.res.util; 002 003 import java.io.IOException; 004 import java.io.InputStream; 005 006 import railo.commons.io.res.Resource; 007 008 public class ResourceInputStream extends InputStream { 009 010 private final Resource res; 011 private final InputStream is; 012 013 public ResourceInputStream(Resource res, InputStream is) { 014 this.res=res; 015 this.is=is; 016 } 017 018 @Override 019 public int read() throws IOException { 020 return is.read(); 021 } 022 023 @Override 024 public int available() throws IOException { 025 return is.available(); 026 } 027 028 @Override 029 public void close() throws IOException { 030 try { 031 is.close(); 032 } 033 finally { 034 res.getResourceProvider().unlock(res); 035 } 036 } 037 038 @Override 039 public void mark(int readlimit) { 040 is.mark(readlimit); 041 } 042 043 @Override 044 public boolean markSupported() { 045 return is.markSupported(); 046 } 047 048 @Override 049 public int read(byte[] b, int off, int len) throws IOException { 050 return is.read(b, off, len); 051 } 052 053 @Override 054 public int read(byte[] b) throws IOException { 055 return is.read(b); 056 } 057 058 @Override 059 public synchronized void reset() throws IOException { 060 is.reset(); 061 } 062 063 @Override 064 public long skip(long n) throws IOException { 065 return is.skip(n); 066 } 067 068 /** 069 * @return the InputStream 070 */ 071 public InputStream getInputStream() { 072 return is; 073 } 074 075 /** 076 * @return the Resource 077 */ 078 public Resource getResource() { 079 return res; 080 } 081 082 }