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