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 /** 024 * @see java.io.InputStream#read() 025 */ 026 public int read() throws IOException { 027 return is.read(); 028 } 029 030 /** 031 * @see java.io.InputStream#available() 032 */ 033 public int available() throws IOException { 034 return is.available(); 035 } 036 037 /** 038 * @see java.io.InputStream#close() 039 */ 040 public void close() throws IOException { 041 is.close(); 042 } 043 044 /** 045 * @see java.io.InputStream#mark(int) 046 */ 047 public synchronized void mark(int readlimit) { 048 is.mark(readlimit); 049 } 050 051 /** 052 * @see java.io.InputStream#markSupported() 053 */ 054 public boolean markSupported() { 055 return is.markSupported(); 056 } 057 058 /** 059 * @see java.io.InputStream#read(byte[], int, int) 060 */ 061 public int read(byte[] b, int off, int len) throws IOException { 062 return is.read(b, off, len); 063 } 064 065 /** 066 * @see java.io.InputStream#read(byte[]) 067 */ 068 public int read(byte[] b) throws IOException { 069 return is.read(b); 070 } 071 072 /** 073 * @see java.io.InputStream#reset() 074 */ 075 public synchronized void reset() throws IOException { 076 is.reset(); 077 } 078 079 /** 080 * @see java.io.InputStream#skip(long) 081 */ 082 public long skip(long n) throws IOException { 083 return is.skip(n); 084 } 085 086 087 /** 088 * @throws Throwable 089 * @see java.lang.Object#finalize() 090 */ 091 public void finalize() throws Throwable { 092 super.finalize(); 093 IOUtil.closeEL(is); 094 } 095 }