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