rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 694 emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java@0d277415ed02
permissions -rw-r--r--
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 -*- */
     2 /*
     3 Copyright (c) 2000-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 org.apidesign.bck2brwsr.emul.zip;
    36 
    37 import org.apidesign.bck2brwsr.emul.lang.System;
    38 
    39 /**
    40  * ZStream
    41  *
    42  * @deprecated  Not for public use in the future.
    43  */
    44 @Deprecated
    45 class ZStream{
    46 
    47   static final private int MAX_WBITS=15;        // 32K LZ77 window
    48   static final private int DEF_WBITS=MAX_WBITS;
    49 
    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;
    55 
    56   static final private int MAX_MEM_LEVEL=9;
    57 
    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;
    67 
    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
    72 
    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
    77 
    78   public String msg;
    79 
    80   Inflate istate; 
    81 
    82   int data_type; // best guess about the data type: ascii or binary
    83 
    84   Checksum adler;
    85 
    86   public ZStream(){
    87     this(new Adler32());
    88   }
    89 
    90   public ZStream(Checksum adler){
    91     this.adler=adler;
    92   }
    93 
    94   public int inflateInit(){
    95     return inflateInit(DEF_WBITS);
    96   }
    97   public int inflateInit(boolean nowrap){
    98     return inflateInit(DEF_WBITS, nowrap);
    99   }
   100   public int inflateInit(int w){
   101     return inflateInit(w, false);
   102   }
   103 
   104   public int inflateInit(int w, boolean nowrap){
   105     istate=new Inflate(this);
   106     return istate.inflateInit(nowrap?-w:w);
   107   }
   108 
   109   public int inflate(int f){
   110     if(istate==null) return Z_STREAM_ERROR;
   111     return istate.inflate(f);
   112   }
   113   public int inflateEnd(){
   114     if(istate==null) return Z_STREAM_ERROR;
   115     int ret=istate.inflateEnd();
   116 //    istate = null;
   117     return ret;
   118   }
   119   
   120   public int inflateSync(){
   121     if(istate == null)
   122       return Z_STREAM_ERROR;
   123     return istate.inflateSync();
   124   }
   125   public int inflateSyncPoint(){
   126     if(istate == null)
   127       return Z_STREAM_ERROR;
   128     return istate.inflateSyncPoint();
   129   }
   130   public int inflateSetDictionary(byte[] dictionary, int dictLength){
   131     if(istate == null)
   132       return Z_STREAM_ERROR;
   133     return istate.inflateSetDictionary(dictionary, dictLength);
   134   }
   135   public boolean inflateFinished(){
   136     return istate.mode==12 /*DONE*/;
   137   }
   138 
   139 
   140   public long getAdler(){
   141     return adler.getValue();
   142   }
   143 
   144   public void free(){
   145     next_in=null;
   146     next_out=null;
   147     msg=null;
   148   }
   149 
   150   public void setOutput(byte[] buf){
   151     setOutput(buf, 0, buf.length); 
   152   }
   153 
   154   public void setOutput(byte[] buf, int off, int len){
   155     next_out = buf;
   156     next_out_index = off;
   157     avail_out = len;
   158   }
   159 
   160   public void setInput(byte[] buf){
   161     setInput(buf, 0, buf.length, false); 
   162   }
   163 
   164   public void setInput(byte[] buf, boolean append){
   165     setInput(buf, 0, buf.length, append); 
   166   }
   167 
   168   public void setInput(byte[] buf, int off, int len, boolean append){
   169     if(len<=0 && append && next_in!=null) return;
   170 
   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);
   175       next_in=tmp;
   176       next_in_index=0;
   177       avail_in+=len;
   178     }
   179     else{
   180       next_in=buf;
   181       next_in_index=off;
   182       avail_in=len;
   183     }
   184   }
   185 
   186   public byte[] getNextIn(){
   187     return next_in;
   188   }
   189 
   190   public void setNextIn(byte[] next_in){
   191     this.next_in = next_in;
   192   }
   193 
   194   public int getNextInIndex(){
   195     return next_in_index;
   196   }
   197 
   198   public void setNextInIndex(int next_in_index){
   199     this.next_in_index = next_in_index;
   200   }
   201 
   202   public int getAvailIn(){
   203     return avail_in;
   204   }
   205 
   206   public void setAvailIn(int avail_in){
   207     this.avail_in = avail_in;
   208   }
   209 
   210   public byte[] getNextOut(){
   211     return next_out;
   212   }
   213 
   214   public void setNextOut(byte[] next_out){
   215     this.next_out = next_out;
   216   }
   217 
   218   public int getNextOutIndex(){
   219     return next_out_index;
   220   }
   221 
   222   public void setNextOutIndex(int next_out_index){
   223     this.next_out_index = next_out_index;
   224   }
   225 
   226   public int getAvailOut(){
   227     return avail_out;
   228 
   229   }
   230 
   231   public void setAvailOut(int avail_out){
   232     this.avail_out = avail_out;
   233   }
   234 
   235   public long getTotalOut(){
   236     return total_out;
   237   }
   238 
   239   public long getTotalIn(){
   240     return total_in;
   241   }
   242 
   243   public String getMessage(){
   244     return msg;
   245   }
   246 
   247   /**
   248    * Those methods are expected to be override by Inflater and Deflater.
   249    * In the future, they will become abstract methods.
   250    */ 
   251   public int end(){ return Z_OK; }
   252   public boolean finished(){ return false; }
   253 }