1 Clazz.declarePackage ("JU");
\r
2 Clazz.load (["JU.InfTree"], "JU.InfBlocks", ["JU.InfCodes"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
27 this.inftree = null;
\r
29 Clazz.instantialize (this, arguments);
\r
30 }, JU, "InfBlocks");
\r
31 Clazz.prepareFields (c$, function () {
\r
32 this.bb = Clazz.newIntArray (1, 0);
\r
33 this.tb = Clazz.newIntArray (1, 0);
\r
34 this.bl = Clazz.newIntArray (1, 0);
\r
35 this.bd = Clazz.newIntArray (1, 0);
\r
36 this.tli = Clazz.newIntArray (1, 0);
\r
37 this.tdi = Clazz.newIntArray (1, 0);
\r
38 this.inftree = new JU.InfTree ();
\r
40 Clazz.makeConstructor (c$,
\r
43 this.codes = new JU.InfCodes (this.z, this);
\r
44 this.hufts = Clazz.newIntArray (4320, 0);
\r
45 this.window = Clazz.newByteArray (w, 0);
\r
47 this.check = (z.istate.wrap == 0) ? false : true;
\r
50 this.tl = Clazz.newArray(1, null);
\r
51 this.td = Clazz.newArray(1, null);
\r
53 }, "JU.ZStream,~N");
\r
54 Clazz.defineMethod (c$, "reset",
\r
56 if (this.mode == 6) {
\r
57 this.codes.free (this.z);
\r
61 this.read = this.write = 0;
\r
63 this.z.checksum.reset ();
\r
65 Clazz.defineMethod (c$, "proc",
\r
75 p = this.z.next_in_index;
\r
76 n = this.z.avail_in;
\r
81 m = (q < this.read ? this.read - q - 1 : this.end - q);
\r
83 switch (this.mode) {
\r
91 this.z.avail_in = n;
\r
92 this.z.total_in += p - this.z.next_in_index;
\r
93 this.z.next_in_index = p;
\r
95 return this.inflate_flush (r);
\r
97 b |= (this.z.next_in[p++] & 0xff) << k;
\r
114 JU.InfTree.inflate_trees_fixed (this.bl, this.bd, this.tl, this.td, this.z);
\r
115 this.codes.init (this.bl[0], this.bd[0], this.tl[0], 0, this.td[0], 0);
\r
132 this.z.msg = "invalid block type";
\r
136 this.z.avail_in = n;
\r
137 this.z.total_in += p - this.z.next_in_index;
\r
138 this.z.next_in_index = p;
\r
140 return this.inflate_flush (r);
\r
150 this.z.avail_in = n;
\r
151 this.z.total_in += p - this.z.next_in_index;
\r
152 this.z.next_in_index = p;
\r
154 return this.inflate_flush (r);
\r
156 b |= (this.z.next_in[p++] & 0xff) << k;
\r
159 if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
\r
161 this.z.msg = "invalid stored block lengths";
\r
165 this.z.avail_in = n;
\r
166 this.z.total_in += p - this.z.next_in_index;
\r
167 this.z.next_in_index = p;
\r
169 return this.inflate_flush (r);
\r
170 }this.left = (b & 0xffff);
\r
172 this.mode = this.left != 0 ? 2 : (this.last != 0 ? 7 : 0);
\r
178 this.z.avail_in = n;
\r
179 this.z.total_in += p - this.z.next_in_index;
\r
180 this.z.next_in_index = p;
\r
182 return this.inflate_flush (r);
\r
184 if (q == this.end && this.read != 0) {
\r
186 m = (q < this.read ? this.read - q - 1 : this.end - q);
\r
189 r = this.inflate_flush (r);
\r
191 m = (q < this.read ? this.read - q - 1 : this.end - q);
\r
192 if (q == this.end && this.read != 0) {
\r
194 m = (q < this.read ? this.read - q - 1 : this.end - q);
\r
198 this.z.avail_in = n;
\r
199 this.z.total_in += p - this.z.next_in_index;
\r
200 this.z.next_in_index = p;
\r
202 return this.inflate_flush (r);
\r
207 System.arraycopy (this.z.next_in, p, this.window, q, t);
\r
212 if ((this.left -= t) != 0) break;
\r
213 this.mode = this.last != 0 ? 7 : 0;
\r
222 this.z.avail_in = n;
\r
223 this.z.total_in += p - this.z.next_in_index;
\r
224 this.z.next_in_index = p;
\r
226 return this.inflate_flush (r);
\r
228 b |= (this.z.next_in[p++] & 0xff) << k;
\r
231 this.table = t = (b & 0x3fff);
\r
232 if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
\r
234 this.z.msg = "too many length or distance symbols";
\r
238 this.z.avail_in = n;
\r
239 this.z.total_in += p - this.z.next_in_index;
\r
240 this.z.next_in_index = p;
\r
242 return this.inflate_flush (r);
\r
243 }t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
\r
244 if (this.blens == null || this.blens.length < t) {
\r
245 this.blens = Clazz.newIntArray (t, 0);
\r
247 for (var i = 0; i < t; i++) {
\r
256 while (this.index < 4 + (this.table >>> 10)) {
\r
263 this.z.avail_in = n;
\r
264 this.z.total_in += p - this.z.next_in_index;
\r
265 this.z.next_in_index = p;
\r
267 return this.inflate_flush (r);
\r
269 b |= (this.z.next_in[p++] & 0xff) << k;
\r
272 this.blens[JU.InfBlocks.border[this.index++]] = b & 7;
\r
277 while (this.index < 19) {
\r
278 this.blens[JU.InfBlocks.border[this.index++]] = 0;
\r
281 t = this.inftree.inflate_trees_bits (this.blens, this.bb, this.tb, this.hufts, this.z);
\r
289 this.z.avail_in = n;
\r
290 this.z.total_in += p - this.z.next_in_index;
\r
291 this.z.next_in_index = p;
\r
293 return this.inflate_flush (r);
\r
299 if (!(this.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))) {
\r
311 this.z.avail_in = n;
\r
312 this.z.total_in += p - this.z.next_in_index;
\r
313 this.z.next_in_index = p;
\r
315 return this.inflate_flush (r);
\r
317 b |= (this.z.next_in[p++] & 0xff) << k;
\r
320 t = this.hufts[(this.tb[0] + (b & JU.InfBlocks.inflate_mask[t])) * 3 + 1];
\r
321 c = this.hufts[(this.tb[0] + (b & JU.InfBlocks.inflate_mask[t])) * 3 + 2];
\r
325 this.blens[this.index++] = c;
\r
327 i = c == 18 ? 7 : c - 14;
\r
328 j = c == 18 ? 11 : 3;
\r
329 while (k < (t + i)) {
\r
335 this.z.avail_in = n;
\r
336 this.z.total_in += p - this.z.next_in_index;
\r
337 this.z.next_in_index = p;
\r
339 return this.inflate_flush (r);
\r
341 b |= (this.z.next_in[p++] & 0xff) << k;
\r
346 j += (b & JU.InfBlocks.inflate_mask[i]);
\r
351 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
\r
354 this.z.msg = "invalid bit length repeat";
\r
358 this.z.avail_in = n;
\r
359 this.z.total_in += p - this.z.next_in_index;
\r
360 this.z.next_in_index = p;
\r
362 return this.inflate_flush (r);
\r
363 }c = c == 16 ? this.blens[i - 1] : 0;
\r
365 this.blens[i++] = c;
\r
366 } while (--j != 0);
\r
374 t = this.inftree.inflate_trees_dynamic (257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), this.blens, this.bl, this.bd, this.tli, this.tdi, this.hufts, this.z);
\r
382 this.z.avail_in = n;
\r
383 this.z.total_in += p - this.z.next_in_index;
\r
384 this.z.next_in_index = p;
\r
386 return this.inflate_flush (r);
\r
387 }this.codes.init (this.bl[0], this.bd[0], this.hufts, this.tli[0], this.hufts, this.tdi[0]);
\r
392 this.z.avail_in = n;
\r
393 this.z.total_in += p - this.z.next_in_index;
\r
394 this.z.next_in_index = p;
\r
396 if ((r = this.codes.proc (r)) != 1) {
\r
397 return this.inflate_flush (r);
\r
399 this.codes.free (this.z);
\r
400 p = this.z.next_in_index;
\r
401 n = this.z.avail_in;
\r
405 m = (q < this.read ? this.read - q - 1 : this.end - q);
\r
406 if (this.last == 0) {
\r
412 r = this.inflate_flush (r);
\r
414 m = (q < this.read ? this.read - q - 1 : this.end - q);
\r
415 if (this.read != this.write) {
\r
418 this.z.avail_in = n;
\r
419 this.z.total_in += p - this.z.next_in_index;
\r
420 this.z.next_in_index = p;
\r
422 return this.inflate_flush (r);
\r
428 this.z.avail_in = n;
\r
429 this.z.total_in += p - this.z.next_in_index;
\r
430 this.z.next_in_index = p;
\r
432 return this.inflate_flush (r);
\r
437 this.z.avail_in = n;
\r
438 this.z.total_in += p - this.z.next_in_index;
\r
439 this.z.next_in_index = p;
\r
441 return this.inflate_flush (r);
\r
446 this.z.avail_in = n;
\r
447 this.z.total_in += p - this.z.next_in_index;
\r
448 this.z.next_in_index = p;
\r
450 return this.inflate_flush (r);
\r
454 Clazz.defineMethod (c$, "free",
\r
457 this.window = null;
\r
460 Clazz.defineMethod (c$, "set_dictionary",
\r
461 function (d, start, n) {
\r
462 System.arraycopy (d, start, this.window, 0, n);
\r
463 this.read = this.write = n;
\r
465 Clazz.defineMethod (c$, "sync_point",
\r
467 return this.mode == 1 ? 1 : 0;
\r
469 Clazz.defineMethod (c$, "inflate_flush",
\r
474 p = this.z.next_out_index;
\r
476 n = ((q <= this.write ? this.write : this.end) - q);
\r
477 if (n > this.z.avail_out) n = this.z.avail_out;
\r
478 if (n != 0 && r == -5) r = 0;
\r
479 this.z.avail_out -= n;
\r
480 this.z.total_out += n;
\r
481 if (this.check && n > 0) {
\r
482 this.z.checksum.update (this.window, q, n);
\r
483 }System.arraycopy (this.window, q, this.z.next_out, p, n);
\r
486 if (q == this.end) {
\r
488 if (this.write == this.end) this.write = 0;
\r
489 n = this.write - q;
\r
490 if (n > this.z.avail_out) n = this.z.avail_out;
\r
491 if (n != 0 && r == -5) r = 0;
\r
492 this.z.avail_out -= n;
\r
493 this.z.total_out += n;
\r
494 if (this.check && n > 0) {
\r
495 this.z.checksum.update (this.window, q, n);
\r
496 }System.arraycopy (this.window, q, this.z.next_out, p, n);
\r
499 }this.z.next_out_index = p;
\r
503 Clazz.defineStatics (c$,
\r
505 "inflate_mask", Clazz.newIntArray (-1, [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff]),
\r
506 "border", Clazz.newIntArray (-1, [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]),
\r
509 "Z_STREAM_ERROR", -2,
\r
510 "Z_DATA_ERROR", -3,
\r