001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.commons.net.http.httpclient4; 020 021import java.io.ByteArrayInputStream; 022import java.io.IOException; 023import java.io.InputStream; 024import java.util.zip.GZIPInputStream; 025 026import lucee.commons.io.IOUtil; 027 028public class CachingGZIPInputStream extends InputStream { 029 030 private final byte[] barr; 031 private GZIPInputStream is; 032 033 public CachingGZIPInputStream(InputStream is) throws IOException { 034 barr=IOUtil.toBytes(is,true); 035 this.is=new GZIPInputStream(new ByteArrayInputStream(barr)); 036 } 037 038 @Override 039 public int available() throws IOException { 040 return is.available(); 041 } 042 043 @Override 044 public void close() throws IOException { 045 is.close(); 046 } 047 048 @Override 049 public void mark(int readlimit) { 050 is.mark(readlimit); 051 } 052 053 @Override 054 public boolean markSupported() { 055 return is.markSupported(); 056 } 057 058 @Override 059 public int read(byte[] b, int off, int len) throws IOException { 060 return is.read(b, off, len); 061 } 062 063 @Override 064 public int read(byte[] b) throws IOException { 065 return is.read(b); 066 } 067 068 @Override 069 public synchronized void reset() throws IOException { 070 is.reset(); 071 } 072 073 @Override 074 public long skip(long n) throws IOException { 075 return is.skip(n); 076 } 077 078 @Override 079 public int read() throws IOException { 080 return is.read(); 081 } 082 083 public InputStream getRawData() { 084 return new ByteArrayInputStream(barr); 085 } 086}