1 Clazz.declarePackage ("java.util.zip");
\r
2 Clazz.load (["java.util.zip.InflaterInputStream", "$.ZipConstants", "$.CRC32"], "java.util.zip.ZipInputStream", ["java.io.EOFException", "$.IOException", "$.PushbackInputStream", "java.lang.IllegalArgumentException", "$.IndexOutOfBoundsException", "$.Long", "$.NullPointerException", "java.util.zip.Inflater", "$.ZipEntry", "$.ZipException"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
9 this.$closed = false;
\r
10 this.entryEOF = false;
\r
12 this.byteTest = null;
\r
14 Clazz.instantialize (this, arguments);
\r
15 }, java.util.zip, "ZipInputStream", java.util.zip.InflaterInputStream, java.util.zip.ZipConstants);
\r
16 Clazz.prepareFields (c$, function () {
\r
17 this.crc = new java.util.zip.CRC32 ();
\r
18 this.tmpbuf = Clazz.newByteArray (512, 0);
\r
19 this.byteTest = Clazz.newByteArray (-1, [0x20]);
\r
20 this.$b = Clazz.newByteArray (256, 0);
\r
22 Clazz.defineMethod (c$, "ensureOpen",
\r
25 throw new java.io.IOException ("Stream closed");
\r
27 Clazz.makeConstructor (c$,
\r
29 Clazz.superConstructor (this, java.util.zip.ZipInputStream, [ new java.io.PushbackInputStream ($in, 1024), java.util.zip.ZipInputStream.newInflater (), 512]);
\r
30 var charset = "UTF-8";
\r
32 String.instantialize (this.byteTest, charset);
\r
34 if (Clazz.exceptionOf (e, java.io.UnsupportedEncodingException)) {
\r
35 throw new NullPointerException ("charset is invalid");
\r
41 }, "java.io.InputStream");
\r
42 c$.newInflater = Clazz.defineMethod (c$, "newInflater",
\r
44 return new java.util.zip.Inflater ().init (0, true);
\r
46 Clazz.defineMethod (c$, "getNextEntry",
\r
49 if (this.entry != null) {
\r
52 this.inflater = this.inf = java.util.zip.ZipInputStream.newInflater ();
\r
53 if ((this.entry = this.readLOC ()) == null) {
\r
55 }if (this.entry.method == 0) {
\r
56 this.remaining = this.entry.size;
\r
57 }this.entryEOF = false;
\r
60 Clazz.defineMethod (c$, "closeEntry",
\r
63 while (this.read (this.tmpbuf, 0, this.tmpbuf.length) != -1) {
\r
65 this.entryEOF = true;
\r
67 Clazz.overrideMethod (c$, "available",
\r
70 return (this.entryEOF ? 0 : 1);
\r
72 Clazz.overrideMethod (c$, "read",
\r
73 function (b, off, len) {
\r
75 if (off < 0 || len < 0 || off > b.length - len) {
\r
76 throw new IndexOutOfBoundsException ();
\r
77 } else if (len == 0) {
\r
79 }if (this.entry == null) {
\r
81 }switch (this.entry.method) {
\r
83 len = this.readInf (b, off, len);
\r
85 this.readEnd (this.entry);
\r
86 this.entryEOF = true;
\r
89 this.crc.update (b, off, len);
\r
92 if (this.remaining <= 0) {
\r
93 this.entryEOF = true;
\r
96 }if (len > this.remaining) {
\r
97 len = this.remaining;
\r
98 }len = this.$in.read (b, off, len);
\r
100 throw new java.util.zip.ZipException ("unexpected EOF");
\r
101 }this.crc.update (b, off, len);
\r
102 this.remaining -= len;
\r
103 if (this.remaining == 0 && this.entry.crc != this.crc.getValue ()) {
\r
104 throw new java.util.zip.ZipException ("invalid entry CRC (expected 0x" + Long.toHexString (this.entry.crc) + " but got 0x" + Long.toHexString (this.crc.getValue ()) + ")");
\r
107 throw new java.util.zip.ZipException ("invalid compression method");
\r
110 Clazz.overrideMethod (c$, "skip",
\r
113 throw new IllegalArgumentException ("negative skip length");
\r
114 }this.ensureOpen ();
\r
115 var max = Math.min (n, 2147483647);
\r
117 while (total < max) {
\r
118 var len = max - total;
\r
119 if (len > this.tmpbuf.length) {
\r
120 len = this.tmpbuf.length;
\r
121 }len = this.read (this.tmpbuf, 0, len);
\r
123 this.entryEOF = true;
\r
129 Clazz.defineMethod (c$, "close",
\r
131 if (!this.$closed) {
\r
132 Clazz.superCall (this, java.util.zip.ZipInputStream, "close", []);
\r
133 this.$closed = true;
\r
135 Clazz.defineMethod (c$, "readLOC",
\r
138 this.readFully (this.tmpbuf, 0, 30);
\r
140 if (Clazz.exceptionOf (e, java.io.EOFException)) {
\r
146 if (java.util.zip.ZipInputStream.get32 (this.tmpbuf, 0) != 67324752) {
\r
148 }this.flag = java.util.zip.ZipInputStream.get16 (this.tmpbuf, 6);
\r
149 var len = java.util.zip.ZipInputStream.get16 (this.tmpbuf, 26);
\r
150 var blen = this.$b.length;
\r
152 do blen = blen * 2;
\r
153 while (len > blen);
\r
154 this.$b = Clazz.newByteArray (blen, 0);
\r
155 }this.readFully (this.$b, 0, len);
\r
156 var e = this.createZipEntry (((this.flag & 2048) != 0) ? this.toStringUTF8 (this.$b, len) : this.toStringb2 (this.$b, len));
\r
157 if ((this.flag & 1) == 1) {
\r
158 throw new java.util.zip.ZipException ("encrypted ZIP entry not supported");
\r
159 }e.method = java.util.zip.ZipInputStream.get16 (this.tmpbuf, 8);
\r
160 e.time = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 10);
\r
161 if ((this.flag & 8) == 8) {
\r
162 if (e.method != 8) {
\r
163 throw new java.util.zip.ZipException ("only DEFLATED entries can have EXT descriptor");
\r
165 e.crc = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 14);
\r
166 e.csize = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 18);
\r
167 e.size = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 22);
\r
168 }len = java.util.zip.ZipInputStream.get16 (this.tmpbuf, 28);
\r
170 var bb = Clazz.newByteArray (len, 0);
\r
171 this.readFully (bb, 0, len);
\r
173 if (e.csize == 4294967295 || e.size == 4294967295) {
\r
175 while (off + 4 < len) {
\r
176 var sz = java.util.zip.ZipInputStream.get16 (bb, off + 2);
\r
177 if (java.util.zip.ZipInputStream.get16 (bb, off) == 1) {
\r
179 if (sz < 16 || (off + sz) > len) {
\r
181 }e.size = java.util.zip.ZipInputStream.get64 (bb, off);
\r
182 e.csize = java.util.zip.ZipInputStream.get64 (bb, off + 8);
\r
188 Clazz.defineMethod (c$, "toStringUTF8",
\r
189 function (b2, len) {
\r
191 return String.instantialize (b2, 0, len, this.zc);
\r
193 if (Clazz.exceptionOf (e, java.io.UnsupportedEncodingException)) {
\r
194 return this.toStringb2 (b2, len);
\r
200 Clazz.defineMethod (c$, "toStringb2",
\r
201 function (b2, len) {
\r
202 return String.instantialize (b2, 0, len);
\r
204 Clazz.defineMethod (c$, "createZipEntry",
\r
206 return new java.util.zip.ZipEntry (name);
\r
208 Clazz.defineMethod (c$, "readEnd",
\r
210 var n = this.inf.getAvailIn ();
\r
212 (this.$in).unread (this.buf, this.len - n, n);
\r
214 }if ((this.flag & 8) == 8) {
\r
215 if (this.inf.getTotalOut () > 4294967295 || this.inf.getTotalIn () > 4294967295) {
\r
216 this.readFully (this.tmpbuf, 0, 24);
\r
217 var sig = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 0);
\r
218 if (sig != 134695760) {
\r
220 e.csize = java.util.zip.ZipInputStream.get64 (this.tmpbuf, 4);
\r
221 e.size = java.util.zip.ZipInputStream.get64 (this.tmpbuf, 12);
\r
222 (this.$in).unread (this.tmpbuf, 19, 4);
\r
224 e.crc = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 4);
\r
225 e.csize = java.util.zip.ZipInputStream.get64 (this.tmpbuf, 8);
\r
226 e.size = java.util.zip.ZipInputStream.get64 (this.tmpbuf, 16);
\r
228 this.readFully (this.tmpbuf, 0, 16);
\r
229 var sig = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 0);
\r
230 if (sig != 134695760) {
\r
232 e.csize = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 4);
\r
233 e.size = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 8);
\r
234 (this.$in).unread (this.tmpbuf, 11, 4);
\r
236 e.crc = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 4);
\r
237 e.csize = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 8);
\r
238 e.size = java.util.zip.ZipInputStream.get32 (this.tmpbuf, 12);
\r
239 }}}if (e.size != this.inf.getTotalOut ()) {
\r
240 throw new java.util.zip.ZipException ("invalid entry size (expected " + e.size + " but got " + this.inf.getTotalOut () + " bytes)");
\r
241 }if (e.csize != this.inf.getTotalIn ()) {
\r
242 throw new java.util.zip.ZipException ("invalid entry compressed size (expected " + e.csize + " but got " + this.inf.getTotalIn () + " bytes)");
\r
243 }if (e.crc != this.crc.getValue ()) {
\r
244 throw new java.util.zip.ZipException ("invalid entry CRC (expected 0x" + Long.toHexString (e.crc) + " but got 0x" + Long.toHexString (this.crc.getValue ()) + ")");
\r
245 }}, "java.util.zip.ZipEntry");
\r
246 Clazz.defineMethod (c$, "readFully",
\r
247 function (b, off, len) {
\r
249 var n = this.$in.read (b, off, len);
\r
251 throw new java.io.EOFException ();
\r
256 c$.get16 = Clazz.defineMethod (c$, "get16",
\r
257 function (b, off) {
\r
258 return (b[off] & 0xff) | ((b[off + 1] & 0xff) << 8);
\r
260 c$.get32 = Clazz.defineMethod (c$, "get32",
\r
261 function (b, off) {
\r
262 return (java.util.zip.ZipInputStream.get16 (b, off) | (java.util.zip.ZipInputStream.get16 (b, off + 2) << 16)) & 0xffffffff;
\r
264 c$.get64 = Clazz.defineMethod (c$, "get64",
\r
265 function (b, off) {
\r
266 return java.util.zip.ZipInputStream.get32 (b, off) | (java.util.zip.ZipInputStream.get32 (b, off + 4) << 32);
\r
268 Clazz.defineStatics (c$,
\r