jaroslav@694: /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ jaroslav@694: /* jaroslav@694: Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved. jaroslav@694: jaroslav@694: Redistribution and use in source and binary forms, with or without jaroslav@694: modification, are permitted provided that the following conditions are met: jaroslav@694: jaroslav@694: 1. Redistributions of source code must retain the above copyright notice, jaroslav@694: this list of conditions and the following disclaimer. jaroslav@694: jaroslav@694: 2. Redistributions in binary form must reproduce the above copyright jaroslav@694: notice, this list of conditions and the following disclaimer in jaroslav@694: the documentation and/or other materials provided with the distribution. jaroslav@694: jaroslav@694: 3. The names of the authors may not be used to endorse or promote products jaroslav@694: derived from this software without specific prior written permission. jaroslav@694: jaroslav@694: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, jaroslav@694: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND jaroslav@694: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, jaroslav@694: INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, jaroslav@694: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT jaroslav@694: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, jaroslav@694: OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF jaroslav@694: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING jaroslav@694: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, jaroslav@694: EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jaroslav@694: */ jaroslav@694: /* jaroslav@694: * This program is based on zlib-1.1.3, so all credit should go authors jaroslav@694: * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) jaroslav@694: * and contributors of zlib. jaroslav@694: */ jaroslav@694: jaroslav@694: package org.apidesign.bck2brwsr.emul.zip; jaroslav@694: jaroslav@694: import org.apidesign.bck2brwsr.emul.lang.System; jaroslav@694: jaroslav@694: /** jaroslav@694: * ZStream jaroslav@694: * jaroslav@694: * @deprecated Not for public use in the future. jaroslav@694: */ jaroslav@694: @Deprecated jaroslav@694: class ZStream{ jaroslav@694: jaroslav@694: static final private int MAX_WBITS=15; // 32K LZ77 window jaroslav@694: static final private int DEF_WBITS=MAX_WBITS; jaroslav@694: jaroslav@694: static final private int Z_NO_FLUSH=0; jaroslav@694: static final private int Z_PARTIAL_FLUSH=1; jaroslav@694: static final private int Z_SYNC_FLUSH=2; jaroslav@694: static final private int Z_FULL_FLUSH=3; jaroslav@694: static final private int Z_FINISH=4; jaroslav@694: jaroslav@694: static final private int MAX_MEM_LEVEL=9; jaroslav@694: jaroslav@694: static final private int Z_OK=0; jaroslav@694: static final private int Z_STREAM_END=1; jaroslav@694: static final private int Z_NEED_DICT=2; jaroslav@694: static final private int Z_ERRNO=-1; jaroslav@694: static final private int Z_STREAM_ERROR=-2; jaroslav@694: static final private int Z_DATA_ERROR=-3; jaroslav@694: static final private int Z_MEM_ERROR=-4; jaroslav@694: static final private int Z_BUF_ERROR=-5; jaroslav@694: static final private int Z_VERSION_ERROR=-6; jaroslav@694: jaroslav@694: public byte[] next_in; // next input byte jaroslav@694: public int next_in_index; jaroslav@694: public int avail_in; // number of bytes available at next_in jaroslav@694: public long total_in; // total nb of input bytes read so far jaroslav@694: jaroslav@694: public byte[] next_out; // next output byte should be put there jaroslav@694: public int next_out_index; jaroslav@694: public int avail_out; // remaining free space at next_out jaroslav@694: public long total_out; // total nb of bytes output so far jaroslav@694: jaroslav@694: public String msg; jaroslav@694: jaroslav@694: Inflate istate; jaroslav@694: jaroslav@694: int data_type; // best guess about the data type: ascii or binary jaroslav@694: jaroslav@694: Checksum adler; jaroslav@694: jaroslav@694: public ZStream(){ jaroslav@694: this(new Adler32()); jaroslav@694: } jaroslav@694: jaroslav@694: public ZStream(Checksum adler){ jaroslav@694: this.adler=adler; jaroslav@694: } jaroslav@694: jaroslav@694: public int inflateInit(){ jaroslav@694: return inflateInit(DEF_WBITS); jaroslav@694: } jaroslav@694: public int inflateInit(boolean nowrap){ jaroslav@694: return inflateInit(DEF_WBITS, nowrap); jaroslav@694: } jaroslav@694: public int inflateInit(int w){ jaroslav@694: return inflateInit(w, false); jaroslav@694: } jaroslav@694: jaroslav@694: public int inflateInit(int w, boolean nowrap){ jaroslav@694: istate=new Inflate(this); jaroslav@694: return istate.inflateInit(nowrap?-w:w); jaroslav@694: } jaroslav@694: jaroslav@694: public int inflate(int f){ jaroslav@694: if(istate==null) return Z_STREAM_ERROR; jaroslav@694: return istate.inflate(f); jaroslav@694: } jaroslav@694: public int inflateEnd(){ jaroslav@694: if(istate==null) return Z_STREAM_ERROR; jaroslav@694: int ret=istate.inflateEnd(); jaroslav@694: // istate = null; jaroslav@694: return ret; jaroslav@694: } jaroslav@694: jaroslav@694: public int inflateSync(){ jaroslav@694: if(istate == null) jaroslav@694: return Z_STREAM_ERROR; jaroslav@694: return istate.inflateSync(); jaroslav@694: } jaroslav@694: public int inflateSyncPoint(){ jaroslav@694: if(istate == null) jaroslav@694: return Z_STREAM_ERROR; jaroslav@694: return istate.inflateSyncPoint(); jaroslav@694: } jaroslav@694: public int inflateSetDictionary(byte[] dictionary, int dictLength){ jaroslav@694: if(istate == null) jaroslav@694: return Z_STREAM_ERROR; jaroslav@694: return istate.inflateSetDictionary(dictionary, dictLength); jaroslav@694: } jaroslav@694: public boolean inflateFinished(){ jaroslav@694: return istate.mode==12 /*DONE*/; jaroslav@694: } jaroslav@694: jaroslav@694: jaroslav@694: public long getAdler(){ jaroslav@694: return adler.getValue(); jaroslav@694: } jaroslav@694: jaroslav@694: public void free(){ jaroslav@694: next_in=null; jaroslav@694: next_out=null; jaroslav@694: msg=null; jaroslav@694: } jaroslav@694: jaroslav@694: public void setOutput(byte[] buf){ jaroslav@694: setOutput(buf, 0, buf.length); jaroslav@694: } jaroslav@694: jaroslav@694: public void setOutput(byte[] buf, int off, int len){ jaroslav@694: next_out = buf; jaroslav@694: next_out_index = off; jaroslav@694: avail_out = len; jaroslav@694: } jaroslav@694: jaroslav@694: public void setInput(byte[] buf){ jaroslav@694: setInput(buf, 0, buf.length, false); jaroslav@694: } jaroslav@694: jaroslav@694: public void setInput(byte[] buf, boolean append){ jaroslav@694: setInput(buf, 0, buf.length, append); jaroslav@694: } jaroslav@694: jaroslav@694: public void setInput(byte[] buf, int off, int len, boolean append){ jaroslav@694: if(len<=0 && append && next_in!=null) return; jaroslav@694: jaroslav@694: if(avail_in>0 && append){ jaroslav@694: byte[] tmp = new byte[avail_in+len]; jaroslav@694: System.arraycopy(next_in, next_in_index, tmp, 0, avail_in); jaroslav@694: System.arraycopy(buf, off, tmp, avail_in, len); jaroslav@694: next_in=tmp; jaroslav@694: next_in_index=0; jaroslav@694: avail_in+=len; jaroslav@694: } jaroslav@694: else{ jaroslav@694: next_in=buf; jaroslav@694: next_in_index=off; jaroslav@694: avail_in=len; jaroslav@694: } jaroslav@694: } jaroslav@694: jaroslav@694: public byte[] getNextIn(){ jaroslav@694: return next_in; jaroslav@694: } jaroslav@694: jaroslav@694: public void setNextIn(byte[] next_in){ jaroslav@694: this.next_in = next_in; jaroslav@694: } jaroslav@694: jaroslav@694: public int getNextInIndex(){ jaroslav@694: return next_in_index; jaroslav@694: } jaroslav@694: jaroslav@694: public void setNextInIndex(int next_in_index){ jaroslav@694: this.next_in_index = next_in_index; jaroslav@694: } jaroslav@694: jaroslav@694: public int getAvailIn(){ jaroslav@694: return avail_in; jaroslav@694: } jaroslav@694: jaroslav@694: public void setAvailIn(int avail_in){ jaroslav@694: this.avail_in = avail_in; jaroslav@694: } jaroslav@694: jaroslav@694: public byte[] getNextOut(){ jaroslav@694: return next_out; jaroslav@694: } jaroslav@694: jaroslav@694: public void setNextOut(byte[] next_out){ jaroslav@694: this.next_out = next_out; jaroslav@694: } jaroslav@694: jaroslav@694: public int getNextOutIndex(){ jaroslav@694: return next_out_index; jaroslav@694: } jaroslav@694: jaroslav@694: public void setNextOutIndex(int next_out_index){ jaroslav@694: this.next_out_index = next_out_index; jaroslav@694: } jaroslav@694: jaroslav@694: public int getAvailOut(){ jaroslav@694: return avail_out; jaroslav@694: jaroslav@694: } jaroslav@694: jaroslav@694: public void setAvailOut(int avail_out){ jaroslav@694: this.avail_out = avail_out; jaroslav@694: } jaroslav@694: jaroslav@694: public long getTotalOut(){ jaroslav@694: return total_out; jaroslav@694: } jaroslav@694: jaroslav@694: public long getTotalIn(){ jaroslav@694: return total_in; jaroslav@694: } jaroslav@694: jaroslav@694: public String getMessage(){ jaroslav@694: return msg; jaroslav@694: } jaroslav@694: jaroslav@694: /** jaroslav@694: * Those methods are expected to be override by Inflater and Deflater. jaroslav@694: * In the future, they will become abstract methods. jaroslav@694: */ jaroslav@694: public int end(){ return Z_OK; } jaroslav@694: public boolean finished(){ return false; } jaroslav@694: }