001    package railo.commons.io.auto;
002    
003    import java.io.IOException;
004    import java.io.InputStream;
005    
006    import railo.commons.io.IOUtil;
007    
008    /**
009     * Close the Stream automaticlly when object will destroyed by the garbage
010     */
011    public final class AutoCloseInputStream extends InputStream {
012            
013            private final InputStream is;
014    
015            /**
016             * constructor of the class
017             * @param is
018             */
019            public AutoCloseInputStream(InputStream is) {
020                    this.is=is;
021            }
022            
023            @Override
024            public int read() throws IOException {
025                    return is.read();
026            }
027    
028            @Override
029            public int available() throws IOException {
030                    return is.available();
031            }
032    
033            @Override
034            public void close() throws IOException {
035                    is.close();
036            }
037    
038            @Override
039            public synchronized 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            @Override
070            public void finalize() throws Throwable {
071                    super.finalize();
072                    IOUtil.closeEL(is);
073            }
074    }