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            /**
019             * @see java.io.InputStream#read()
020             */
021            public int read() throws IOException {
022                    return is.read();
023            }
024    
025            /**
026             * @see java.io.InputStream#available()
027             */
028            public int available() throws IOException {
029                    return is.available();
030            }
031    
032            /**
033             * @see java.io.InputStream#close()
034             */
035            public void close() throws IOException {
036                    try {
037                            is.close();
038                    }
039                    finally {
040                            res.getResourceProvider().unlock(res);
041                    }
042            }
043    
044            /**
045             * @see java.io.InputStream#mark(int)
046             */
047            public void mark(int readlimit) {
048                    is.mark(readlimit);
049            }
050    
051            /**
052             *
053             * @see java.io.InputStream#markSupported()
054             */
055            public boolean markSupported() {
056                    return is.markSupported();
057            }
058    
059            /**
060             *
061             * @see java.io.InputStream#read(byte[], int, int)
062             */
063            public int read(byte[] b, int off, int len) throws IOException {
064                    return is.read(b, off, len);
065            }
066    
067            /**
068             *
069             * @see java.io.InputStream#read(byte[])
070             */
071            public int read(byte[] b) throws IOException {
072                    return is.read(b);
073            }
074    
075            /**
076             *
077             * @see java.io.InputStream#reset()
078             */
079            public synchronized void reset() throws IOException {
080                    is.reset();
081            }
082    
083            /**
084             *
085             * @see java.io.InputStream#skip(long)
086             */
087            public long skip(long n) throws IOException {
088                    return is.skip(n);
089            }
090    
091            /**
092             * @return the InputStream
093             */
094            public InputStream getInputStream() {
095                    return is;
096            }
097    
098            /**
099             * @return the Resource
100             */
101            public Resource getResource() {
102                    return res;
103            }
104    
105    }