1 Clazz.declarePackage ("java.util.zip");
\r
2 Clazz.load (["java.util.zip.DeflaterOutputStream", "$.ZipConstants", "java.util.Hashtable", "java.util.zip.CRC32", "JU.Lst"], "java.util.zip.ZipOutputStream", ["JU.ZStream", "java.io.IOException", "java.lang.Boolean", "$.IllegalArgumentException", "$.IndexOutOfBoundsException", "$.Long", "java.util.zip.Deflater", "$.ZipException"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
5 this.xentries = null;
\r
10 this.comment = null;
\r
12 this.finished = false;
\r
13 this.$closed = false;
\r
14 Clazz.instantialize (this, arguments);
\r
15 }, java.util.zip, "ZipOutputStream", java.util.zip.DeflaterOutputStream, java.util.zip.ZipConstants);
\r
16 Clazz.prepareFields (c$, function () {
\r
17 this.xentries = new JU.Lst ();
\r
18 this.names = new java.util.Hashtable ();
\r
19 this.crc = new java.util.zip.CRC32 ();
\r
21 c$.version = Clazz.defineMethod (c$, "version",
\r
29 throw new java.util.zip.ZipException ("unsupported compression method");
\r
31 }, "java.util.zip.ZipEntry");
\r
32 Clazz.defineMethod (c$, "ensureOpen",
\r
35 throw new java.io.IOException ("Stream closed");
\r
37 Clazz.makeConstructor (c$,
\r
39 Clazz.superConstructor (this, java.util.zip.ZipOutputStream, []);
\r
41 Clazz.defineMethod (c$, "setZOS",
\r
43 this.setDOS (out, java.util.zip.ZipOutputStream.newDeflater ());
\r
45 }, "java.io.OutputStream");
\r
46 c$.newDeflater = Clazz.defineMethod (c$, "newDeflater",
\r
48 return ( new java.util.zip.Deflater (2147483647)).init (-1, 0, true);
\r
50 Clazz.defineMethod (c$, "setComment",
\r
51 function (comment) {
\r
52 if (comment != null) {
\r
53 this.comment = JU.ZStream.getBytes (comment);
\r
54 if (this.comment.length > 0xffff) throw new IllegalArgumentException ("ZIP file comment too long.");
\r
56 Clazz.defineMethod (c$, "putNextEntry",
\r
59 if (this.current != null) {
\r
61 }if (e.time == -1) {
\r
62 e.setTime (System.currentTimeMillis ());
\r
63 }if (e.method == -1) {
\r
64 e.method = this.method;
\r
68 if (e.size == -1 || e.csize == -1 || e.crc == -1) e.flag = 8;
\r
73 } else if (e.csize == -1) {
\r
75 } else if (e.size != e.csize) {
\r
76 throw new java.util.zip.ZipException ("STORED entry where compressed != uncompressed size");
\r
77 }if (e.size == -1 || e.crc == -1) {
\r
78 throw new java.util.zip.ZipException ("STORED entry missing size, compressed size, or crc-32");
\r
81 throw new java.util.zip.ZipException ("unsupported compression method");
\r
83 if (this.names.containsKey (e.name)) {
\r
84 throw new java.util.zip.ZipException ("duplicate entry: " + e.name);
\r
85 }this.names.put (e.name, Boolean.TRUE);
\r
88 this.current.offset = this.written;
\r
89 this.xentries.addLast (this.current);
\r
90 this.writeLOC (this.current);
\r
91 }, "java.util.zip.ZipEntry");
\r
92 Clazz.defineMethod (c$, "closeEntry",
\r
95 if (this.current != null) {
\r
96 var e = this.current;
\r
99 this.deflater.finish ();
\r
100 Clazz.superCall (this, java.util.zip.ZipOutputStream, "finish", []);
\r
101 if ((e.flag & 8) == 0) {
\r
102 if (e.size != this.deflater.getBytesRead ()) {
\r
103 throw new java.util.zip.ZipException ("invalid entry size (expected " + e.size + " but got " + this.deflater.getBytesRead () + " bytes)");
\r
104 }if (e.csize != this.deflater.getBytesWritten ()) {
\r
105 throw new java.util.zip.ZipException ("invalid entry compressed size (expected " + e.csize + " but got " + this.deflater.getBytesWritten () + " bytes)");
\r
106 }if (e.crc != this.crc.getValue ()) {
\r
107 throw new java.util.zip.ZipException ("invalid entry CRC-32 (expected 0x" + Long.toHexString (e.crc) + " but got 0x" + Long.toHexString (this.crc.getValue ()) + ")");
\r
109 e.size = this.deflater.getBytesRead ();
\r
110 e.csize = this.deflater.getBytesWritten ();
\r
111 e.crc = this.crc.getValue ();
\r
113 }this.deflater = java.util.zip.ZipOutputStream.newDeflater ();
\r
114 this.written += e.csize;
\r
117 if (e.size != this.written - this.locoff) {
\r
118 throw new java.util.zip.ZipException ("invalid entry size (expected " + e.size + " but got " + (this.written - this.locoff) + " bytes)");
\r
119 }if (e.crc != this.crc.getValue ()) {
\r
120 throw new java.util.zip.ZipException ("invalid entry crc-32 (expected 0x" + Long.toHexString (e.crc) + " but got 0x" + Long.toHexString (this.crc.getValue ()) + ")");
\r
123 throw new java.util.zip.ZipException ("invalid compression method");
\r
126 this.current = null;
\r
128 Clazz.defineMethod (c$, "write",
\r
129 function (b, off, len) {
\r
130 this.ensureOpen ();
\r
131 if (off < 0 || len < 0 || off > b.length - len) {
\r
132 throw new IndexOutOfBoundsException ();
\r
133 } else if (len == 0) {
\r
135 }if (this.current == null) {
\r
136 throw new java.util.zip.ZipException ("no current ZIP entry");
\r
137 }var entry = this.current;
\r
138 switch (entry.method) {
\r
140 Clazz.superCall (this, java.util.zip.ZipOutputStream, "write", [b, off, len]);
\r
143 this.written += len;
\r
144 if (this.written - this.locoff > entry.size) {
\r
145 throw new java.util.zip.ZipException ("attempt to write past end of STORED entry");
\r
146 }this.out.write (this.buffer, 0, len);
\r
149 throw new java.util.zip.ZipException ("invalid compression method");
\r
151 this.crc.update (b, off, len);
\r
153 Clazz.defineMethod (c$, "finish",
\r
155 this.ensureOpen ();
\r
156 if (this.finished) {
\r
158 }if (this.current != null) {
\r
159 this.closeEntry ();
\r
160 }var off = this.written;
\r
161 for (var xentry, $xentry = this.xentries.iterator (); $xentry.hasNext () && ((xentry = $xentry.next ()) || true);) this.writeCEN (xentry);
\r
163 this.writeEND (off, this.written - off);
\r
164 this.finished = true;
\r
166 Clazz.defineMethod (c$, "close",
\r
168 if (!this.$closed) {
\r
169 Clazz.superCall (this, java.util.zip.ZipOutputStream, "close", []);
\r
170 this.$closed = true;
\r
172 Clazz.defineMethod (c$, "writeLOC",
\r
176 var elen = (e.extra != null) ? e.extra.length : 0;
\r
177 var hasZip64 = false;
\r
178 this.writeInt (67324752);
\r
179 if ((flag & 8) == 8) {
\r
180 this.writeShort (java.util.zip.ZipOutputStream.version (e));
\r
181 this.writeShort (flag);
\r
182 this.writeShort (e.method);
\r
183 this.writeInt (e.time);
\r
188 if (e.csize >= 4294967295 || e.size >= 4294967295) {
\r
190 this.writeShort (45);
\r
192 this.writeShort (java.util.zip.ZipOutputStream.version (e));
\r
193 }this.writeShort (flag);
\r
194 this.writeShort (e.method);
\r
195 this.writeInt (e.time);
\r
196 this.writeInt (e.crc);
\r
198 this.writeInt (4294967295);
\r
199 this.writeInt (4294967295);
\r
202 this.writeInt (e.csize);
\r
203 this.writeInt (e.size);
\r
204 }}var nameBytes = JU.ZStream.getBytes (e.name);
\r
205 this.writeShort (nameBytes.length);
\r
206 this.writeShort (elen);
\r
207 this.writeBytes (nameBytes, 0, nameBytes.length);
\r
209 this.writeShort (1);
\r
210 this.writeShort (16);
\r
211 this.writeLong (e.size);
\r
212 this.writeLong (e.csize);
\r
213 }if (e.extra != null) {
\r
214 this.writeBytes (e.extra, 0, e.extra.length);
\r
215 }this.locoff = this.written;
\r
216 }, "java.util.zip.ZipEntry");
\r
217 Clazz.defineMethod (c$, "writeEXT",
\r
219 this.writeInt (134695760);
\r
220 this.writeInt (e.crc);
\r
221 if (e.csize >= 4294967295 || e.size >= 4294967295) {
\r
222 this.writeLong (e.csize);
\r
223 this.writeLong (e.size);
\r
225 this.writeInt (e.csize);
\r
226 this.writeInt (e.size);
\r
227 }}, "java.util.zip.ZipEntry");
\r
228 Clazz.defineMethod (c$, "writeCEN",
\r
232 var version = java.util.zip.ZipOutputStream.version (e);
\r
233 var csize = e.csize;
\r
235 var offset = entry.offset;
\r
237 var hasZip64 = false;
\r
238 if (e.csize >= 4294967295) {
\r
239 csize = 4294967295;
\r
242 }if (e.size >= 4294967295) {
\r
246 }if (entry.offset >= 4294967295) {
\r
247 offset = 4294967295;
\r
250 }this.writeInt (33639248);
\r
252 this.writeShort (45);
\r
253 this.writeShort (45);
\r
255 this.writeShort (version);
\r
256 this.writeShort (version);
\r
257 }this.writeShort (flag);
\r
258 this.writeShort (e.method);
\r
259 this.writeInt (e.time);
\r
260 this.writeInt (e.crc);
\r
261 this.writeInt (csize);
\r
262 this.writeInt (size);
\r
263 var nameBytes = JU.ZStream.getBytes (e.name);
\r
264 this.writeShort (nameBytes.length);
\r
266 this.writeShort (e64len + 4 + (e.extra != null ? e.extra.length : 0));
\r
268 this.writeShort (e.extra != null ? e.extra.length : 0);
\r
270 if (e.comment != null) {
\r
271 commentBytes = JU.ZStream.getBytes (e.comment);
\r
272 this.writeShort (Math.min (commentBytes.length, 0xffff));
\r
274 commentBytes = null;
\r
275 this.writeShort (0);
\r
276 }this.writeShort (0);
\r
277 this.writeShort (0);
\r
279 this.writeInt (offset);
\r
280 this.writeBytes (nameBytes, 0, nameBytes.length);
\r
282 this.writeShort (1);
\r
283 this.writeShort (e64len);
\r
284 if (size == 4294967295) this.writeLong (e.size);
\r
285 if (csize == 4294967295) this.writeLong (e.csize);
\r
286 if (offset == 4294967295) this.writeLong (entry.offset);
\r
287 }if (e.extra != null) {
\r
288 this.writeBytes (e.extra, 0, e.extra.length);
\r
289 }if (commentBytes != null) {
\r
290 this.writeBytes (commentBytes, 0, Math.min (commentBytes.length, 0xffff));
\r
291 }}, "java.util.zip.ZipEntry");
\r
292 Clazz.defineMethod (c$, "writeEND",
\r
293 function (off, len) {
\r
294 var hasZip64 = false;
\r
297 if (xlen >= 4294967295) {
\r
300 }if (xoff >= 4294967295) {
\r
303 }var count = this.xentries.size ();
\r
304 if (count >= 65535) {
\r
308 var off64 = this.written;
\r
309 this.writeInt (101075792);
\r
310 this.writeLong (44);
\r
311 this.writeShort (45);
\r
312 this.writeShort (45);
\r
315 this.writeLong (this.xentries.size ());
\r
316 this.writeLong (this.xentries.size ());
\r
317 this.writeLong (len);
\r
318 this.writeLong (off);
\r
319 this.writeInt (117853008);
\r
321 this.writeLong (off64);
\r
323 }this.writeInt (101010256);
\r
324 this.writeShort (0);
\r
325 this.writeShort (0);
\r
326 this.writeShort (count);
\r
327 this.writeShort (count);
\r
328 this.writeInt (xlen);
\r
329 this.writeInt (xoff);
\r
330 if (this.comment != null) {
\r
331 this.writeShort (this.comment.length);
\r
332 this.writeBytes (this.comment, 0, this.comment.length);
\r
334 this.writeShort (0);
\r
336 Clazz.defineMethod (c$, "writeShort",
\r
338 var out = this.out;
\r
340 out.writeByteAsInt((v >>> 0) & 0xff);
\r
341 out.writeByteAsInt((v >>> 8) & 0xff);
\r
342 }this.written += 2;
\r
344 Clazz.defineMethod (c$, "writeInt",
\r
346 var out = this.out;
\r
348 out.writeByteAsInt((v >>> 0) & 0xff);
\r
349 out.writeByteAsInt((v >>> 8) & 0xff);
\r
350 out.writeByteAsInt((v >>> 16) & 0xff);
\r
351 out.writeByteAsInt((v >>> 24) & 0xff);
\r
352 }this.written += 4;
\r
354 Clazz.defineMethod (c$, "writeLong",
\r
356 var out = this.out;
\r
358 out.writeByteAsInt((v >>> 0) & 0xff);
\r
359 out.writeByteAsInt((v >>> 8) & 0xff);
\r
360 out.writeByteAsInt((v >>> 16) & 0xff);
\r
361 out.writeByteAsInt((v >>> 24) & 0xff);
\r
362 out.writeByteAsInt(0);
\r
363 out.writeByteAsInt(0);
\r
364 out.writeByteAsInt(0);
\r
365 out.writeByteAsInt(0);
\r
366 }this.written += 8;
\r
368 Clazz.defineMethod (c$, "writeBytes",
\r
369 function (b, off, len) {
\r
370 this.out.write (b, off, len);
\r
371 this.written += len;
\r
373 Clazz.defineStatics (c$,
\r