Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
1 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
3 Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
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.
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.
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.
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.
35 package org.apidesign.bck2brwsr.emul.zip;
37 import org.apidesign.bck2brwsr.emul.lang.System;
42 * @deprecated Not for public use in the future.
47 static final private int MAX_WBITS=15; // 32K LZ77 window
48 static final private int DEF_WBITS=MAX_WBITS;
50 static final private int Z_NO_FLUSH=0;
51 static final private int Z_PARTIAL_FLUSH=1;
52 static final private int Z_SYNC_FLUSH=2;
53 static final private int Z_FULL_FLUSH=3;
54 static final private int Z_FINISH=4;
56 static final private int MAX_MEM_LEVEL=9;
58 static final private int Z_OK=0;
59 static final private int Z_STREAM_END=1;
60 static final private int Z_NEED_DICT=2;
61 static final private int Z_ERRNO=-1;
62 static final private int Z_STREAM_ERROR=-2;
63 static final private int Z_DATA_ERROR=-3;
64 static final private int Z_MEM_ERROR=-4;
65 static final private int Z_BUF_ERROR=-5;
66 static final private int Z_VERSION_ERROR=-6;
68 public byte[] next_in; // next input byte
69 public int next_in_index;
70 public int avail_in; // number of bytes available at next_in
71 public long total_in; // total nb of input bytes read so far
73 public byte[] next_out; // next output byte should be put there
74 public int next_out_index;
75 public int avail_out; // remaining free space at next_out
76 public long total_out; // total nb of bytes output so far
82 int data_type; // best guess about the data type: ascii or binary
90 public ZStream(Checksum adler){
94 public int inflateInit(){
95 return inflateInit(DEF_WBITS);
97 public int inflateInit(boolean nowrap){
98 return inflateInit(DEF_WBITS, nowrap);
100 public int inflateInit(int w){
101 return inflateInit(w, false);
104 public int inflateInit(int w, boolean nowrap){
105 istate=new Inflate(this);
106 return istate.inflateInit(nowrap?-w:w);
109 public int inflate(int f){
110 if(istate==null) return Z_STREAM_ERROR;
111 return istate.inflate(f);
113 public int inflateEnd(){
114 if(istate==null) return Z_STREAM_ERROR;
115 int ret=istate.inflateEnd();
120 public int inflateSync(){
122 return Z_STREAM_ERROR;
123 return istate.inflateSync();
125 public int inflateSyncPoint(){
127 return Z_STREAM_ERROR;
128 return istate.inflateSyncPoint();
130 public int inflateSetDictionary(byte[] dictionary, int dictLength){
132 return Z_STREAM_ERROR;
133 return istate.inflateSetDictionary(dictionary, dictLength);
135 public boolean inflateFinished(){
136 return istate.mode==12 /*DONE*/;
140 public long getAdler(){
141 return adler.getValue();
150 public void setOutput(byte[] buf){
151 setOutput(buf, 0, buf.length);
154 public void setOutput(byte[] buf, int off, int len){
156 next_out_index = off;
160 public void setInput(byte[] buf){
161 setInput(buf, 0, buf.length, false);
164 public void setInput(byte[] buf, boolean append){
165 setInput(buf, 0, buf.length, append);
168 public void setInput(byte[] buf, int off, int len, boolean append){
169 if(len<=0 && append && next_in!=null) return;
171 if(avail_in>0 && append){
172 byte[] tmp = new byte[avail_in+len];
173 System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
174 System.arraycopy(buf, off, tmp, avail_in, len);
186 public byte[] getNextIn(){
190 public void setNextIn(byte[] next_in){
191 this.next_in = next_in;
194 public int getNextInIndex(){
195 return next_in_index;
198 public void setNextInIndex(int next_in_index){
199 this.next_in_index = next_in_index;
202 public int getAvailIn(){
206 public void setAvailIn(int avail_in){
207 this.avail_in = avail_in;
210 public byte[] getNextOut(){
214 public void setNextOut(byte[] next_out){
215 this.next_out = next_out;
218 public int getNextOutIndex(){
219 return next_out_index;
222 public void setNextOutIndex(int next_out_index){
223 this.next_out_index = next_out_index;
226 public int getAvailOut(){
231 public void setAvailOut(int avail_out){
232 this.avail_out = avail_out;
235 public long getTotalOut(){
239 public long getTotalIn(){
243 public String getMessage(){
248 * Those methods are expected to be override by Inflater and Deflater.
249 * In the future, they will become abstract methods.
251 public int end(){ return Z_OK; }
252 public boolean finished(){ return false; }