1 Clazz.declarePackage ("JU");
2 Clazz.load (["java.lang.Exception"], "JU.Inflate", ["JU.Adler32", "$.CRC32", "$.GZIPHeader", "$.InfBlocks", "java.io.ByteArrayOutputStream"], function () {
3 c$ = Clazz.decorateAsClass (function () {
17 if (!Clazz.isClassDefined ("JU.Inflate.Return")) {
18 JU.Inflate.$Inflate$Return$ ();
20 this.tmp_string = null;
21 Clazz.instantialize (this, arguments);
23 Clazz.prepareFields (c$, function () {
24 this.crcbuf = Clazz.newByteArray (4, 0);
26 Clazz.defineMethod (c$, "reset",
30 Clazz.defineMethod (c$, "inflateReset",
32 if (this.z == null) return -2;
33 this.z.total_in = this.z.total_out = 0;
40 Clazz.defineMethod (c$, "inflateEnd",
42 if (this.blocks != null) {
46 Clazz.makeConstructor (c$,
50 Clazz.defineMethod (c$, "inflateInit",
58 this.wrap = (w >> 4) + 1;
60 }if (w < 8 || w > 15) {
63 }if (this.blocks != null && this.wbits != w) {
67 this.blocks = new JU.InfBlocks (this.z, 1 << w);
71 Clazz.defineMethod (c$, "inflate",
75 if (this.z == null || this.z.next_in == null) {
76 if (f == 4 && this.mode == 14) return 0;
87 r = this.readBytes (2, r, f);
89 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
95 if ((this.wrap & 2) != 0 && this.need == 0x8b1f) {
96 this.z.checksum = new JU.CRC32 ();
97 this.checksum (2, this.need);
98 if (this.gheader == null) this.gheader = new JU.GZIPHeader ();
102 this.method = (this.need) & 0xff;
103 b = ((this.need >> 8)) & 0xff;
104 if ((this.wrap & 1) == 0 || (((this.method << 8) + b) % 31) != 0) {
106 this.z.msg = "incorrect header check";
108 }if ((this.method & 0xf) != 8) {
110 this.z.msg = "unknown compression method";
112 }if ((this.method >> 4) + 8 > this.wbits) {
114 this.z.msg = "invalid window size";
116 }this.z.checksum = new JU.Adler32 ();
122 if (this.z.avail_in == 0) return r;
126 this.need = ((this.z.next_in[this.z.next_in_index++] & 0xff) << 24) & 0xff000000;
129 if (this.z.avail_in == 0) return r;
133 this.need += ((this.z.next_in[this.z.next_in_index++] & 0xff) << 16) & 0xff0000;
136 if (this.z.avail_in == 0) return r;
140 this.need += ((this.z.next_in[this.z.next_in_index++] & 0xff) << 8) & 0xff00;
143 if (this.z.avail_in == 0) return r;
147 this.need += (this.z.next_in[this.z.next_in_index++] & 0xff);
148 this.z.checksum.resetLong (this.need);
153 this.z.msg = "need dictionary";
157 r = this.blocks.proc (r);
167 this.was = this.z.checksum.getValue ();
168 this.blocks.reset ();
169 if (this.wrap == 0) {
174 if (this.z.avail_in == 0) return r;
178 this.need = ((this.z.next_in[this.z.next_in_index++] & 0xff) << 24) & 0xff000000;
181 if (this.z.avail_in == 0) return r;
185 this.need += ((this.z.next_in[this.z.next_in_index++] & 0xff) << 16) & 0xff0000;
188 if (this.z.avail_in == 0) return r;
192 this.need += ((this.z.next_in[this.z.next_in_index++] & 0xff) << 8) & 0xff00;
195 if (this.z.avail_in == 0) return r;
199 this.need += (this.z.next_in[this.z.next_in_index++] & 0xff);
200 if (this.flags != 0) {
201 this.need = ((this.need & 0xff000000) >> 24 | (this.need & 0x00ff0000) >> 8 | (this.need & 0x0000ff00) << 8 | (this.need & 0x0000ffff) << 24) & 0xffffffff;
202 }if (((this.was)) != ((this.need))) {
203 this.z.msg = "incorrect data check";
204 } else if (this.flags != 0 && this.gheader != null) {
205 this.gheader.crc = this.need;
208 if (this.wrap != 0 && this.flags != 0) {
210 r = this.readBytes (4, r, f);
212 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
218 if (this.z.msg != null && this.z.msg.equals ("incorrect data check")) {
222 }if (this.need != (this.z.total_out & 0xffffffff)) {
223 this.z.msg = "incorrect length check";
228 if (this.z.msg != null && this.z.msg.equals ("incorrect data check")) {
239 r = this.readBytes (2, r, f);
241 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
247 this.flags = (this.need) & 0xffff;
248 if ((this.flags & 0xff) != 8) {
249 this.z.msg = "unknown compression method";
252 }if ((this.flags & 0xe000) != 0) {
253 this.z.msg = "unknown header flags set";
256 }if ((this.flags & 0x0200) != 0) {
257 this.checksum (2, this.need);
261 r = this.readBytes (4, r, f);
263 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
269 if (this.gheader != null) this.gheader.time = this.need;
270 if ((this.flags & 0x0200) != 0) {
271 this.checksum (4, this.need);
275 r = this.readBytes (2, r, f);
277 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
283 if (this.gheader != null) {
284 this.gheader.xflags = (this.need) & 0xff;
285 this.gheader.os = ((this.need) >> 8) & 0xff;
286 }if ((this.flags & 0x0200) != 0) {
287 this.checksum (2, this.need);
290 if ((this.flags & 0x0400) != 0) {
292 r = this.readBytes (2, r, f);
294 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
300 if (this.gheader != null) {
301 this.gheader.extra = Clazz.newByteArray ((this.need) & 0xffff, 0);
302 }if ((this.flags & 0x0200) != 0) {
303 this.checksum (2, this.need);
304 }} else if (this.gheader != null) {
305 this.gheader.extra = null;
308 if ((this.flags & 0x0400) != 0) {
310 r = this.readBytes (r, f);
311 if (this.gheader != null) {
312 var foo = this.tmp_string.toByteArray ();
313 this.tmp_string = null;
314 if (foo.length == this.gheader.extra.length) {
315 System.arraycopy (foo, 0, this.gheader.extra, 0, foo.length);
317 this.z.msg = "bad extra field length";
321 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
327 } else if (this.gheader != null) {
328 this.gheader.extra = null;
331 if ((this.flags & 0x0800) != 0) {
333 r = this.readString (r, f);
334 if (this.gheader != null) {
335 this.gheader.name = this.tmp_string.toByteArray ();
336 }this.tmp_string = null;
338 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
344 } else if (this.gheader != null) {
345 this.gheader.name = null;
348 if ((this.flags & 0x1000) != 0) {
350 r = this.readString (r, f);
351 if (this.gheader != null) {
352 this.gheader.comment = this.tmp_string.toByteArray ();
353 }this.tmp_string = null;
355 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
361 } else if (this.gheader != null) {
362 this.gheader.comment = null;
365 if ((this.flags & 0x0200) != 0) {
367 r = this.readBytes (2, r, f);
369 if (Clazz.exceptionOf (e, JU.Inflate.Return)) {
375 if (this.gheader != null) {
376 this.gheader.hcrc = (this.need & 0xffff);
377 }if (this.need != (this.z.checksum.getValue () & 0xffff)) {
379 this.z.msg = "header crc mismatch";
382 }}this.z.checksum = new JU.CRC32 ();
390 Clazz.defineMethod (c$, "inflateSetDictionary",
391 function (dictionary, dictLength) {
392 if (this.z == null || (this.mode != 6 && this.wrap != 0)) {
395 var length = dictLength;
396 if (this.mode == 6) {
397 var adler_need = this.z.checksum.getValue ();
398 this.z.checksum.reset ();
399 this.z.checksum.update (dictionary, 0, dictLength);
400 if (this.z.checksum.getValue () != adler_need) {
402 }}this.z.checksum.reset ();
403 if (length >= (1 << this.wbits)) {
404 length = (1 << this.wbits) - 1;
405 index = dictLength - length;
406 }this.blocks.set_dictionary (dictionary, index, length);
410 Clazz.defineMethod (c$, "inflateSync",
417 if (this.z == null) return -2;
418 if (this.mode != 13) {
421 }if ((n = this.z.avail_in) == 0) return -5;
422 p = this.z.next_in_index;
424 while (n != 0 && m < 4) {
425 if (this.z.next_in[p] == JU.Inflate.mark[m]) {
427 } else if (this.z.next_in[p] != 0) {
434 this.z.total_in += p - this.z.next_in_index;
435 this.z.next_in_index = p;
440 }r = this.z.total_in;
441 w = this.z.total_out;
442 this.inflateReset ();
444 this.z.total_out = w;
448 Clazz.defineMethod (c$, "inflateSyncPoint",
450 if (this.z == null || this.blocks == null) return -2;
451 return this.blocks.sync_point ();
453 Clazz.defineMethod (c$, "readBytes",
455 if (this.need_bytes == -1) {
458 }while (this.need_bytes > 0) {
459 if (this.z.avail_in == 0) {
460 throw Clazz.innerTypeInstance (JU.Inflate.Return, this, null, r);
464 this.need = this.need | ((this.z.next_in[this.z.next_in_index++] & 0xff) << ((n - this.need_bytes) * 8));
470 this.need &= 0xffffffff;
471 }this.need_bytes = -1;
474 Clazz.defineMethod (c$, "readString",
476 if (this.tmp_string == null) {
477 this.tmp_string = new java.io.ByteArrayOutputStream ();
480 if (this.z.avail_in == 0) {
481 throw Clazz.innerTypeInstance (JU.Inflate.Return, this, null, r);
485 b = this.z.next_in[this.z.next_in_index];
486 if (b != 0) this.tmp_string.write (this.z.next_in, this.z.next_in_index, 1);
487 this.z.checksum.update (this.z.next_in, this.z.next_in_index, 1);
488 this.z.next_in_index++;
492 Clazz.defineMethod (c$, "readBytes",
494 if (this.tmp_string == null) {
495 this.tmp_string = new java.io.ByteArrayOutputStream ();
496 }while (this.need > 0) {
497 if (this.z.avail_in == 0) {
498 throw Clazz.innerTypeInstance (JU.Inflate.Return, this, null, r);
502 this.tmp_string.write (this.z.next_in, this.z.next_in_index, 1);
503 this.z.checksum.update (this.z.next_in, this.z.next_in_index, 1);
504 this.z.next_in_index++;
509 Clazz.defineMethod (c$, "checksum",
511 for (var i = 0; i < n; i++) {
512 this.crcbuf[i] = (v & 0xff);
515 this.z.checksum.update (this.crcbuf, 0, n);
517 Clazz.defineMethod (c$, "getGZIPHeader",
521 Clazz.defineMethod (c$, "inParsingHeader",
542 c$.$Inflate$Return$ = function () {
544 c$ = Clazz.decorateAsClass (function () {
545 Clazz.prepareCallback (this, arguments);
547 Clazz.instantialize (this, arguments);
548 }, JU.Inflate, "Return", Exception);
549 Clazz.makeConstructor (c$,
551 Clazz.superConstructor (this, JU.Inflate.Return, []);
556 Clazz.defineStatics (c$,
559 "Z_PARTIAL_FLUSH", 1,
567 "Z_STREAM_ERROR", -2,
592 "mark", Clazz.newByteArray (-1, [0, 0, 0xff, 0xff]));