emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java
branchmodel
changeset 877 3392f250c784
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java	Fri Mar 22 16:59:47 2013 +0100
     1.3 @@ -0,0 +1,253 @@
     1.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
     1.5 +/*
     1.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
     1.7 +
     1.8 +Redistribution and use in source and binary forms, with or without
     1.9 +modification, are permitted provided that the following conditions are met:
    1.10 +
    1.11 +  1. Redistributions of source code must retain the above copyright notice,
    1.12 +     this list of conditions and the following disclaimer.
    1.13 +
    1.14 +  2. Redistributions in binary form must reproduce the above copyright 
    1.15 +     notice, this list of conditions and the following disclaimer in 
    1.16 +     the documentation and/or other materials provided with the distribution.
    1.17 +
    1.18 +  3. The names of the authors may not be used to endorse or promote products
    1.19 +     derived from this software without specific prior written permission.
    1.20 +
    1.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    1.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    1.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
    1.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
    1.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
    1.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    1.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.31 + */
    1.32 +/*
    1.33 + * This program is based on zlib-1.1.3, so all credit should go authors
    1.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
    1.35 + * and contributors of zlib.
    1.36 + */
    1.37 +
    1.38 +package org.apidesign.bck2brwsr.emul.zip;
    1.39 +
    1.40 +import org.apidesign.bck2brwsr.emul.lang.System;
    1.41 +
    1.42 +/**
    1.43 + * ZStream
    1.44 + *
    1.45 + * @deprecated  Not for public use in the future.
    1.46 + */
    1.47 +@Deprecated
    1.48 +class ZStream{
    1.49 +
    1.50 +  static final private int MAX_WBITS=15;        // 32K LZ77 window
    1.51 +  static final private int DEF_WBITS=MAX_WBITS;
    1.52 +
    1.53 +  static final private int Z_NO_FLUSH=0;
    1.54 +  static final private int Z_PARTIAL_FLUSH=1;
    1.55 +  static final private int Z_SYNC_FLUSH=2;
    1.56 +  static final private int Z_FULL_FLUSH=3;
    1.57 +  static final private int Z_FINISH=4;
    1.58 +
    1.59 +  static final private int MAX_MEM_LEVEL=9;
    1.60 +
    1.61 +  static final private int Z_OK=0;
    1.62 +  static final private int Z_STREAM_END=1;
    1.63 +  static final private int Z_NEED_DICT=2;
    1.64 +  static final private int Z_ERRNO=-1;
    1.65 +  static final private int Z_STREAM_ERROR=-2;
    1.66 +  static final private int Z_DATA_ERROR=-3;
    1.67 +  static final private int Z_MEM_ERROR=-4;
    1.68 +  static final private int Z_BUF_ERROR=-5;
    1.69 +  static final private int Z_VERSION_ERROR=-6;
    1.70 +
    1.71 +  public byte[] next_in;     // next input byte
    1.72 +  public int next_in_index;
    1.73 +  public int avail_in;       // number of bytes available at next_in
    1.74 +  public long total_in;      // total nb of input bytes read so far
    1.75 +
    1.76 +  public byte[] next_out;    // next output byte should be put there
    1.77 +  public int next_out_index;
    1.78 +  public int avail_out;      // remaining free space at next_out
    1.79 +  public long total_out;     // total nb of bytes output so far
    1.80 +
    1.81 +  public String msg;
    1.82 +
    1.83 +  Inflate istate; 
    1.84 +
    1.85 +  int data_type; // best guess about the data type: ascii or binary
    1.86 +
    1.87 +  Checksum adler;
    1.88 +
    1.89 +  public ZStream(){
    1.90 +    this(new Adler32());
    1.91 +  }
    1.92 +
    1.93 +  public ZStream(Checksum adler){
    1.94 +    this.adler=adler;
    1.95 +  }
    1.96 +
    1.97 +  public int inflateInit(){
    1.98 +    return inflateInit(DEF_WBITS);
    1.99 +  }
   1.100 +  public int inflateInit(boolean nowrap){
   1.101 +    return inflateInit(DEF_WBITS, nowrap);
   1.102 +  }
   1.103 +  public int inflateInit(int w){
   1.104 +    return inflateInit(w, false);
   1.105 +  }
   1.106 +
   1.107 +  public int inflateInit(int w, boolean nowrap){
   1.108 +    istate=new Inflate(this);
   1.109 +    return istate.inflateInit(nowrap?-w:w);
   1.110 +  }
   1.111 +
   1.112 +  public int inflate(int f){
   1.113 +    if(istate==null) return Z_STREAM_ERROR;
   1.114 +    return istate.inflate(f);
   1.115 +  }
   1.116 +  public int inflateEnd(){
   1.117 +    if(istate==null) return Z_STREAM_ERROR;
   1.118 +    int ret=istate.inflateEnd();
   1.119 +//    istate = null;
   1.120 +    return ret;
   1.121 +  }
   1.122 +  
   1.123 +  public int inflateSync(){
   1.124 +    if(istate == null)
   1.125 +      return Z_STREAM_ERROR;
   1.126 +    return istate.inflateSync();
   1.127 +  }
   1.128 +  public int inflateSyncPoint(){
   1.129 +    if(istate == null)
   1.130 +      return Z_STREAM_ERROR;
   1.131 +    return istate.inflateSyncPoint();
   1.132 +  }
   1.133 +  public int inflateSetDictionary(byte[] dictionary, int dictLength){
   1.134 +    if(istate == null)
   1.135 +      return Z_STREAM_ERROR;
   1.136 +    return istate.inflateSetDictionary(dictionary, dictLength);
   1.137 +  }
   1.138 +  public boolean inflateFinished(){
   1.139 +    return istate.mode==12 /*DONE*/;
   1.140 +  }
   1.141 +
   1.142 +
   1.143 +  public long getAdler(){
   1.144 +    return adler.getValue();
   1.145 +  }
   1.146 +
   1.147 +  public void free(){
   1.148 +    next_in=null;
   1.149 +    next_out=null;
   1.150 +    msg=null;
   1.151 +  }
   1.152 +
   1.153 +  public void setOutput(byte[] buf){
   1.154 +    setOutput(buf, 0, buf.length); 
   1.155 +  }
   1.156 +
   1.157 +  public void setOutput(byte[] buf, int off, int len){
   1.158 +    next_out = buf;
   1.159 +    next_out_index = off;
   1.160 +    avail_out = len;
   1.161 +  }
   1.162 +
   1.163 +  public void setInput(byte[] buf){
   1.164 +    setInput(buf, 0, buf.length, false); 
   1.165 +  }
   1.166 +
   1.167 +  public void setInput(byte[] buf, boolean append){
   1.168 +    setInput(buf, 0, buf.length, append); 
   1.169 +  }
   1.170 +
   1.171 +  public void setInput(byte[] buf, int off, int len, boolean append){
   1.172 +    if(len<=0 && append && next_in!=null) return;
   1.173 +
   1.174 +    if(avail_in>0 && append){  
   1.175 +      byte[] tmp = new byte[avail_in+len];
   1.176 +      System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
   1.177 +      System.arraycopy(buf, off, tmp, avail_in, len);
   1.178 +      next_in=tmp;
   1.179 +      next_in_index=0;
   1.180 +      avail_in+=len;
   1.181 +    }
   1.182 +    else{
   1.183 +      next_in=buf;
   1.184 +      next_in_index=off;
   1.185 +      avail_in=len;
   1.186 +    }
   1.187 +  }
   1.188 +
   1.189 +  public byte[] getNextIn(){
   1.190 +    return next_in;
   1.191 +  }
   1.192 +
   1.193 +  public void setNextIn(byte[] next_in){
   1.194 +    this.next_in = next_in;
   1.195 +  }
   1.196 +
   1.197 +  public int getNextInIndex(){
   1.198 +    return next_in_index;
   1.199 +  }
   1.200 +
   1.201 +  public void setNextInIndex(int next_in_index){
   1.202 +    this.next_in_index = next_in_index;
   1.203 +  }
   1.204 +
   1.205 +  public int getAvailIn(){
   1.206 +    return avail_in;
   1.207 +  }
   1.208 +
   1.209 +  public void setAvailIn(int avail_in){
   1.210 +    this.avail_in = avail_in;
   1.211 +  }
   1.212 +
   1.213 +  public byte[] getNextOut(){
   1.214 +    return next_out;
   1.215 +  }
   1.216 +
   1.217 +  public void setNextOut(byte[] next_out){
   1.218 +    this.next_out = next_out;
   1.219 +  }
   1.220 +
   1.221 +  public int getNextOutIndex(){
   1.222 +    return next_out_index;
   1.223 +  }
   1.224 +
   1.225 +  public void setNextOutIndex(int next_out_index){
   1.226 +    this.next_out_index = next_out_index;
   1.227 +  }
   1.228 +
   1.229 +  public int getAvailOut(){
   1.230 +    return avail_out;
   1.231 +
   1.232 +  }
   1.233 +
   1.234 +  public void setAvailOut(int avail_out){
   1.235 +    this.avail_out = avail_out;
   1.236 +  }
   1.237 +
   1.238 +  public long getTotalOut(){
   1.239 +    return total_out;
   1.240 +  }
   1.241 +
   1.242 +  public long getTotalIn(){
   1.243 +    return total_in;
   1.244 +  }
   1.245 +
   1.246 +  public String getMessage(){
   1.247 +    return msg;
   1.248 +  }
   1.249 +
   1.250 +  /**
   1.251 +   * Those methods are expected to be override by Inflater and Deflater.
   1.252 +   * In the future, they will become abstract methods.
   1.253 +   */ 
   1.254 +  public int end(){ return Z_OK; }
   1.255 +  public boolean finished(){ return false; }
   1.256 +}