1 2 29 34 35 package com.jcraft.jzlib; 36 37 final public class ZStream{ 38 39 static final private int MAX_WBITS=15; 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 byte[] next_in; public int next_in_index; 62 public int avail_in; public long total_in; 65 public byte[] next_out; public int next_out_index; 67 public int avail_out; public long total_out; 70 public String msg; 71 72 Deflate dstate; 73 Inflate istate; 74 75 int data_type; 77 public long adler; 78 Adler32 _adler=new Adler32(); 79 80 public int inflateInit(){ 81 return inflateInit(DEF_WBITS); 82 } 83 public int inflateInit(boolean nowrap){ 84 return inflateInit(DEF_WBITS, nowrap); 85 } 86 public int inflateInit(int w){ 87 return inflateInit(w, false); 88 } 89 90 public int inflateInit(int w, boolean nowrap){ 91 istate=new Inflate(); 92 return istate.inflateInit(this, nowrap?-w:w); 93 } 94 95 public int inflate(int f){ 96 if(istate==null) return Z_STREAM_ERROR; 97 return istate.inflate(this, f); 98 } 99 public int inflateEnd(){ 100 if(istate==null) return Z_STREAM_ERROR; 101 int ret=istate.inflateEnd(this); 102 istate = null; 103 return ret; 104 } 105 public int inflateSync(){ 106 if(istate == null) 107 return Z_STREAM_ERROR; 108 return istate.inflateSync(this); 109 } 110 public int inflateSetDictionary(byte[] dictionary, int dictLength){ 111 if(istate == null) 112 return Z_STREAM_ERROR; 113 return istate.inflateSetDictionary(this, dictionary, dictLength); 114 } 115 116 public int deflateInit(int level){ 117 return deflateInit(level, MAX_WBITS); 118 } 119 public int deflateInit(int level, boolean nowrap){ 120 return deflateInit(level, MAX_WBITS, nowrap); 121 } 122 public int deflateInit(int level, int bits){ 123 return deflateInit(level, bits, false); 124 } 125 public int deflateInit(int level, int bits, boolean nowrap){ 126 dstate=new Deflate(); 127 return dstate.deflateInit(this, level, nowrap?-bits:bits); 128 } 129 public int deflate(int flush){ 130 if(dstate==null){ 131 return Z_STREAM_ERROR; 132 } 133 return dstate.deflate(this, flush); 134 } 135 public int deflateEnd(){ 136 if(dstate==null) return Z_STREAM_ERROR; 137 int ret=dstate.deflateEnd(); 138 dstate=null; 139 return ret; 140 } 141 public int deflateParams(int level, int strategy){ 142 if(dstate==null) return Z_STREAM_ERROR; 143 return dstate.deflateParams(this, level, strategy); 144 } 145 public int deflateSetDictionary (byte[] dictionary, int dictLength){ 146 if(dstate == null) 147 return Z_STREAM_ERROR; 148 return dstate.deflateSetDictionary(this, dictionary, dictLength); 149 } 150 151 void flush_pending(){ 156 int len=dstate.pending; 157 158 if(len>avail_out) len=avail_out; 159 if(len==0) return; 160 161 if(dstate.pending_buf.length<=dstate.pending_out || 162 next_out.length<=next_out_index || 163 dstate.pending_buf.length<(dstate.pending_out+len) || 164 next_out.length<(next_out_index+len)){ 165 System.out.println(dstate.pending_buf.length+", "+dstate.pending_out+ 166 ", "+next_out.length+", "+next_out_index+", "+len); 167 System.out.println("avail_out="+avail_out); 168 } 169 170 System.arraycopy(dstate.pending_buf, dstate.pending_out, 171 next_out, next_out_index, len); 172 173 next_out_index+=len; 174 dstate.pending_out+=len; 175 total_out+=len; 176 avail_out-=len; 177 dstate.pending-=len; 178 if(dstate.pending==0){ 179 dstate.pending_out=0; 180 } 181 } 182 183 int read_buf(byte[] buf, int start, int size) { 189 int len=avail_in; 190 191 if(len>size) len=size; 192 if(len==0) return 0; 193 194 avail_in-=len; 195 196 if(dstate.noheader==0) { 197 adler=_adler.adler32(adler, next_in, next_in_index, len); 198 } 199 System.arraycopy(next_in, next_in_index, buf, start, len); 200 next_in_index += len; 201 total_in += len; 202 return len; 203 } 204 205 public void free(){ 206 next_in=null; 207 next_out=null; 208 msg=null; 209 _adler=null; 210 } 211 } 212 | Popular Tags |