1 7 8 package java.util.zip; 9 10 50 public 51 class Inflater { 52 private long strm; 53 private byte[] buf = new byte[0]; 54 private int off, len; 55 private boolean finished; 56 private boolean needDict; 57 58 static { 59 60 initIDs(); 61 } 62 63 74 public Inflater(boolean nowrap) { 75 strm = init(nowrap); 76 } 77 78 81 public Inflater() { 82 this(false); 83 } 84 85 94 public synchronized void setInput(byte[] b, int off, int len) { 95 if (b == null) { 96 throw new NullPointerException (); 97 } 98 if (off < 0 || len < 0 || off > b.length - len) { 99 throw new ArrayIndexOutOfBoundsException (); 100 } 101 this.buf = b; 102 this.off = off; 103 this.len = len; 104 } 105 106 113 public void setInput(byte[] b) { 114 setInput(b, 0, b.length); 115 } 116 117 128 public synchronized void setDictionary(byte[] b, int off, int len) { 129 if (strm == 0 || b == null) { 130 throw new NullPointerException (); 131 } 132 if (off < 0 || len < 0 || off > b.length - len) { 133 throw new ArrayIndexOutOfBoundsException (); 134 } 135 setDictionary(strm, b, off, len); 136 needDict = false; 137 } 138 139 148 public void setDictionary(byte[] b) { 149 setDictionary(b, 0, b.length); 150 } 151 152 158 public synchronized int getRemaining() { 159 return len; 160 } 161 162 168 public synchronized boolean needsInput() { 169 return len <= 0; 170 } 171 172 177 public synchronized boolean needsDictionary() { 178 return needDict; 179 } 180 181 187 public synchronized boolean finished() { 188 return finished; 189 } 190 191 206 public synchronized int inflate(byte[] b, int off, int len) 207 throws DataFormatException 208 { 209 if (b == null) { 210 throw new NullPointerException (); 211 } 212 if (off < 0 || len < 0 || off > b.length - len) { 213 throw new ArrayIndexOutOfBoundsException (); 214 } 215 return inflateBytes(b, off, len); 216 } 217 218 231 public int inflate(byte[] b) throws DataFormatException { 232 return inflate(b, 0, b.length); 233 } 234 235 239 public synchronized int getAdler() { 240 ensureOpen(); 241 return getAdler(strm); 242 } 243 244 253 public int getTotalIn() { 254 return (int) getBytesRead(); 255 } 256 257 262 public synchronized long getBytesRead() { 263 ensureOpen(); 264 return getBytesRead(strm); 265 } 266 267 276 public int getTotalOut() { 277 return (int) getBytesWritten(); 278 } 279 280 285 public synchronized long getBytesWritten() { 286 ensureOpen(); 287 return getBytesWritten(strm); 288 } 289 290 293 public synchronized void reset() { 294 ensureOpen(); 295 reset(strm); 296 finished = false; 297 needDict = false; 298 off = len = 0; 299 } 300 301 308 public synchronized void end() { 309 if (strm != 0) { 310 end(strm); 311 strm = 0; 312 buf = null; 313 } 314 } 315 316 319 protected void finalize() { 320 end(); 321 } 322 323 private void ensureOpen () { 324 if (strm == 0) 325 throw new NullPointerException (); 326 } 327 328 private native static void initIDs(); 329 private native static long init(boolean nowrap); 330 private native static void setDictionary(long strm, byte[] b, int off, 331 int len); 332 private native int inflateBytes(byte[] b, int off, int len) 333 throws DataFormatException ; 334 private native static int getAdler(long strm); 335 private native static long getBytesRead(long strm); 336 private native static long getBytesWritten(long strm); 337 private native static void reset(long strm); 338 private native static void end(long strm); 339 } 340 | Popular Tags |