001 package railo.commons.net.http.httpclient4; 002 003 import java.io.ByteArrayInputStream; 004 import java.io.IOException; 005 import java.io.InputStream; 006 import java.util.zip.GZIPInputStream; 007 008 import railo.commons.io.IOUtil; 009 010 public class CachingGZIPInputStream extends InputStream { 011 012 private final byte[] barr; 013 private GZIPInputStream is; 014 015 public CachingGZIPInputStream(InputStream is) throws IOException { 016 barr=IOUtil.toBytes(is,true); 017 this.is=new GZIPInputStream(new ByteArrayInputStream(barr)); 018 } 019 020 @Override 021 public int available() throws IOException { 022 return is.available(); 023 } 024 025 @Override 026 public void close() throws IOException { 027 is.close(); 028 } 029 030 @Override 031 public void mark(int readlimit) { 032 is.mark(readlimit); 033 } 034 035 @Override 036 public boolean markSupported() { 037 return is.markSupported(); 038 } 039 040 @Override 041 public int read(byte[] b, int off, int len) throws IOException { 042 return is.read(b, off, len); 043 } 044 045 @Override 046 public int read(byte[] b) throws IOException { 047 return is.read(b); 048 } 049 050 @Override 051 public synchronized void reset() throws IOException { 052 is.reset(); 053 } 054 055 @Override 056 public long skip(long n) throws IOException { 057 return is.skip(n); 058 } 059 060 @Override 061 public int read() throws IOException { 062 return is.read(); 063 } 064 065 public InputStream getRawData() { 066 return new ByteArrayInputStream(barr); 067 } 068 }