1 /* |
1 /* |
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
190 public void putNextEntry(ZipEntry e) throws IOException { |
189 public void putNextEntry(ZipEntry e) throws IOException { |
191 ensureOpen(); |
190 ensureOpen(); |
192 if (current != null) { |
191 if (current != null) { |
193 closeEntry(); // close previous entry |
192 closeEntry(); // close previous entry |
194 } |
193 } |
195 if (e.time == -1) { |
194 if (e.xdostime == -1) { |
196 // by default, do NOT use extended timestamps in extra |
195 // by default, do NOT use extended timestamps in extra |
197 // data, for now. |
196 // data, for now. |
198 e.setTime(System.currentTimeMillis()); |
197 e.setTime(System.currentTimeMillis()); |
199 } |
198 } |
200 if (e.method == -1) { |
199 if (e.method == -1) { |
387 ZipEntry e = xentry.entry; |
386 ZipEntry e = xentry.entry; |
388 int flag = e.flag; |
387 int flag = e.flag; |
389 boolean hasZip64 = false; |
388 boolean hasZip64 = false; |
390 int elen = getExtraLen(e.extra); |
389 int elen = getExtraLen(e.extra); |
391 |
390 |
392 // keep a copy of dostime for writeCEN(), otherwise the tz |
|
393 // sensitive local time entries in loc and cen might be |
|
394 // different if the default tz get changed during writeLOC() |
|
395 // and writeCEN() |
|
396 xentry.dostime = javaToDosTime(e.time); |
|
397 |
|
398 writeInt(LOCSIG); // LOC header signature |
391 writeInt(LOCSIG); // LOC header signature |
399 if ((flag & 8) == 8) { |
392 if ((flag & 8) == 8) { |
400 writeShort(version(e)); // version needed to extract |
393 writeShort(version(e)); // version needed to extract |
401 writeShort(flag); // general purpose bit flag |
394 writeShort(flag); // general purpose bit flag |
402 writeShort(e.method); // compression method |
395 writeShort(e.method); // compression method |
403 writeInt(xentry.dostime); // last modification time |
396 writeInt(e.xdostime); // last modification time |
404 // store size, uncompressed size, and crc-32 in data descriptor |
397 // store size, uncompressed size, and crc-32 in data descriptor |
405 // immediately following compressed entry data |
398 // immediately following compressed entry data |
406 writeInt(0); |
399 writeInt(0); |
407 writeInt(0); |
400 writeInt(0); |
408 writeInt(0); |
401 writeInt(0); |
413 } else { |
406 } else { |
414 writeShort(version(e)); // version needed to extract |
407 writeShort(version(e)); // version needed to extract |
415 } |
408 } |
416 writeShort(flag); // general purpose bit flag |
409 writeShort(flag); // general purpose bit flag |
417 writeShort(e.method); // compression method |
410 writeShort(e.method); // compression method |
418 writeInt(xentry.dostime); // last modification time |
411 writeInt(e.xdostime); // last modification time |
419 writeInt(e.crc); // crc-32 |
412 writeInt(e.crc); // crc-32 |
420 if (hasZip64) { |
413 if (hasZip64) { |
421 writeInt(ZIP64_MAGICVAL); |
414 writeInt(ZIP64_MAGICVAL); |
422 writeInt(ZIP64_MAGICVAL); |
415 writeInt(ZIP64_MAGICVAL); |
423 elen += 20; //headid(2) + size(2) + size(8) + csize(8) |
416 elen += 20; //headid(2) + size(2) + size(8) + csize(8) |
520 writeShort(version); // version made by |
513 writeShort(version); // version made by |
521 writeShort(version); // version needed to extract |
514 writeShort(version); // version needed to extract |
522 } |
515 } |
523 writeShort(flag); // general purpose bit flag |
516 writeShort(flag); // general purpose bit flag |
524 writeShort(e.method); // compression method |
517 writeShort(e.method); // compression method |
525 // use the copy in xentry, which has been converted |
518 writeInt(e.xdostime); // last modification time |
526 // from e.time in writeLOC() |
|
527 writeInt(xentry.dostime); // last modification time |
|
528 writeInt(e.crc); // crc-32 |
519 writeInt(e.crc); // crc-32 |
529 writeInt(csize); // compressed size |
520 writeInt(csize); // compressed size |
530 writeInt(size); // uncompressed size |
521 writeInt(size); // uncompressed size |
531 byte[] nameBytes = zc.getBytes(e.name); |
522 byte[] nameBytes = zc.getBytes(e.name); |
532 writeShort(nameBytes.length); |
523 writeShort(nameBytes.length); |