Path: blob/main/src/lwjgl/java/com/jcraft/jzlib/Inflater.java
8650 views
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/*2Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are met:671. Redistributions of source code must retain the above copyright notice,8this list of conditions and the following disclaimer.9102. Redistributions in binary form must reproduce the above copyright11notice, this list of conditions and the following disclaimer in12the documentation and/or other materials provided with the distribution.13143. The names of the authors may not be used to endorse or promote products15derived from this software without specific prior written permission.1617THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,18INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND19FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,20INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,23OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF24LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING25NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,26EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/28/*29* This program is based on zlib-1.1.3, so all credit should go authors30* Jean-loup Gailly([email protected]) and Mark Adler([email protected])31* and contributors of zlib.32*/3334package com.jcraft.jzlib;3536final public class Inflater extends ZStream{3738static final private int MAX_WBITS=15; // 32K LZ77 window39static final private int DEF_WBITS=MAX_WBITS;4041static final private int Z_NO_FLUSH=0;42static final private int Z_PARTIAL_FLUSH=1;43static final private int Z_SYNC_FLUSH=2;44static final private int Z_FULL_FLUSH=3;45static final private int Z_FINISH=4;4647static final private int MAX_MEM_LEVEL=9;4849static final private int Z_OK=0;50static final private int Z_STREAM_END=1;51static final private int Z_NEED_DICT=2;52static final private int Z_ERRNO=-1;53static final private int Z_STREAM_ERROR=-2;54static final private int Z_DATA_ERROR=-3;55static final private int Z_MEM_ERROR=-4;56static final private int Z_BUF_ERROR=-5;57static final private int Z_VERSION_ERROR=-6;5859public Inflater() {60super();61init();62}6364public Inflater(JZlib.WrapperType wrapperType) throws GZIPException {65this(DEF_WBITS, wrapperType);66}6768public Inflater(int w, JZlib.WrapperType wrapperType) throws GZIPException {69super();70int ret = init(w, wrapperType);71if(ret!=Z_OK)72throw new GZIPException(ret+": "+msg);73}7475public Inflater(int w) throws GZIPException {76this(w, false);77}7879public Inflater(boolean nowrap) throws GZIPException {80this(DEF_WBITS, nowrap);81}8283public Inflater(int w, boolean nowrap) throws GZIPException {84super();85int ret = init(w, nowrap);86if(ret!=Z_OK)87throw new GZIPException(ret+": "+msg);88}8990private boolean finished = false;9192public int init(){93return init(DEF_WBITS);94}9596public int init(JZlib.WrapperType wrapperType){97return init(DEF_WBITS, wrapperType);98}99100public int init(int w, JZlib.WrapperType wrapperType) {101boolean nowrap = false;102if(wrapperType == JZlib.W_NONE){103nowrap = true;104}105else if(wrapperType == JZlib.W_GZIP) {106w += 16;107}108else if(wrapperType == JZlib.W_ANY) {109w |= Inflate.INFLATE_ANY;110}111else if(wrapperType == JZlib.W_ZLIB) {112}113return init(w, nowrap);114}115116public int init(boolean nowrap){117return init(DEF_WBITS, nowrap);118}119120public int init(int w){121return init(w, false);122}123124public int init(int w, boolean nowrap){125finished = false;126istate=new Inflate(this);127return istate.inflateInit(nowrap?-w:w);128}129130public int inflate(int f){131if(istate==null) return Z_STREAM_ERROR;132int ret = istate.inflate(f);133if(ret == Z_STREAM_END)134finished = true;135return ret;136}137138public int end(){139finished = true;140if(istate==null) return Z_STREAM_ERROR;141int ret=istate.inflateEnd();142// istate = null;143return ret;144}145146public int sync(){147if(istate == null)148return Z_STREAM_ERROR;149return istate.inflateSync();150}151152public int syncPoint(){153if(istate == null)154return Z_STREAM_ERROR;155return istate.inflateSyncPoint();156}157158public int setDictionary(byte[] dictionary, int dictLength){159if(istate == null)160return Z_STREAM_ERROR;161return istate.inflateSetDictionary(dictionary, dictLength);162}163164public boolean finished(){165return istate.mode==12 /*DONE*/;166}167}168169170