comparison src/com/jcraft/jzlib/Inflater.java @ 357:46c2115ae1c8

update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
author Carl Byington <carl@five-ten-sg.com>
date Fri, 01 Aug 2014 13:34:58 -0700
parents
children
comparison
equal deleted inserted replaced
356:5e91b559b5fe 357:46c2115ae1c8
1 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 /*
3 Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution.
14
15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 /*
30 * This program is based on zlib-1.1.3, so all credit should go authors
31 * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
32 * and contributors of zlib.
33 */
34
35 package com.jcraft.jzlib;
36
37 final public class Inflater extends ZStream{
38
39 static final private int MAX_WBITS=15; // 32K LZ77 window
40 static final private int DEF_WBITS=MAX_WBITS;
41
42 static final private int Z_NO_FLUSH=0;
43 static final private int Z_PARTIAL_FLUSH=1;
44 static final private int Z_SYNC_FLUSH=2;
45 static final private int Z_FULL_FLUSH=3;
46 static final private int Z_FINISH=4;
47
48 static final private int MAX_MEM_LEVEL=9;
49
50 static final private int Z_OK=0;
51 static final private int Z_STREAM_END=1;
52 static final private int Z_NEED_DICT=2;
53 static final private int Z_ERRNO=-1;
54 static final private int Z_STREAM_ERROR=-2;
55 static final private int Z_DATA_ERROR=-3;
56 static final private int Z_MEM_ERROR=-4;
57 static final private int Z_BUF_ERROR=-5;
58 static final private int Z_VERSION_ERROR=-6;
59
60 public Inflater() {
61 super();
62 init();
63 }
64
65 public Inflater(JZlib.WrapperType wrapperType) throws GZIPException {
66 this(DEF_WBITS, wrapperType);
67 }
68
69 public Inflater(int w, JZlib.WrapperType wrapperType) throws GZIPException {
70 super();
71 int ret = init(w, wrapperType);
72 if(ret!=Z_OK)
73 throw new GZIPException(ret+": "+msg);
74 }
75
76 public Inflater(int w) throws GZIPException {
77 this(w, false);
78 }
79
80 public Inflater(boolean nowrap) throws GZIPException {
81 this(DEF_WBITS, nowrap);
82 }
83
84 public Inflater(int w, boolean nowrap) throws GZIPException {
85 super();
86 int ret = init(w, nowrap);
87 if(ret!=Z_OK)
88 throw new GZIPException(ret+": "+msg);
89 }
90
91 private boolean finished = false;
92
93 public int init(){
94 return init(DEF_WBITS);
95 }
96
97 public int init(JZlib.WrapperType wrapperType){
98 return init(DEF_WBITS, wrapperType);
99 }
100
101 public int init(int w, JZlib.WrapperType wrapperType) {
102 boolean nowrap = false;
103 if(wrapperType == JZlib.W_NONE){
104 nowrap = true;
105 }
106 else if(wrapperType == JZlib.W_GZIP) {
107 w += 16;
108 }
109 else if(wrapperType == JZlib.W_ANY) {
110 w |= Inflate.INFLATE_ANY;
111 }
112 else if(wrapperType == JZlib.W_ZLIB) {
113 }
114 return init(w, nowrap);
115 }
116
117 public int init(boolean nowrap){
118 return init(DEF_WBITS, nowrap);
119 }
120
121 public int init(int w){
122 return init(w, false);
123 }
124
125 public int init(int w, boolean nowrap){
126 finished = false;
127 istate=new Inflate(this);
128 return istate.inflateInit(nowrap?-w:w);
129 }
130
131 public int inflate(int f){
132 if(istate==null) return Z_STREAM_ERROR;
133 int ret = istate.inflate(f);
134 if(ret == Z_STREAM_END)
135 finished = true;
136 return ret;
137 }
138
139 public int end(){
140 finished = true;
141 if(istate==null) return Z_STREAM_ERROR;
142 int ret=istate.inflateEnd();
143 // istate = null;
144 return ret;
145 }
146
147 public int sync(){
148 if(istate == null)
149 return Z_STREAM_ERROR;
150 return istate.inflateSync();
151 }
152
153 public int syncPoint(){
154 if(istate == null)
155 return Z_STREAM_ERROR;
156 return istate.inflateSyncPoint();
157 }
158
159 public int setDictionary(byte[] dictionary, int dictLength){
160 if(istate == null)
161 return Z_STREAM_ERROR;
162 return istate.inflateSetDictionary(dictionary, dictLength);
163 }
164
165 public boolean finished(){
166 return istate.mode==12 /*DONE*/;
167 }
168 }