1 /*
2 * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
550 public Stream<? extends ZipEntry> stream() {
551 return StreamSupport.stream(Spliterators.spliterator(
552 new ZipEntryIterator(), size(),
553 Spliterator.ORDERED | Spliterator.DISTINCT |
554 Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
555 }
556
557 private ZipEntry getZipEntry(String name, long jzentry) {
558 ZipEntry e = new ZipEntry();
559 e.flag = getEntryFlag(jzentry); // get the flag first
560 if (name != null) {
561 e.name = name;
562 } else {
563 byte[] bname = getEntryBytes(jzentry, JZENTRY_NAME);
564 if (!zc.isUTF8() && (e.flag & EFS) != 0) {
565 e.name = zc.toStringUTF8(bname, bname.length);
566 } else {
567 e.name = zc.toString(bname, bname.length);
568 }
569 }
570 e.crc = getEntryCrc(jzentry);
571 e.size = getEntrySize(jzentry);
572 e. csize = getEntryCSize(jzentry);
573 e.method = getEntryMethod(jzentry);
574 e.extra = getEntryBytes(jzentry, JZENTRY_EXTRA);
575 if (e.extra != null) {
576 byte[] extra = e.extra;
577 int len = e.extra.length;
578 int off = 0;
579 while (off + 4 < len) {
580 int pos = off;
581 int tag = get16(extra, pos);
582 int sz = get16(extra, pos + 2);
583 pos += 4;
584 if (pos + sz > len) // invalid data
585 break;
586 switch (tag) {
587 case EXTID_NTFS:
588 pos += 4; // reserved 4 bytes
589 if (get16(extra, pos) != 0x0001 || get16(extra, pos + 2) != 24)
590 break;
591 e.mtime = winToJavaTime(get64(extra, pos + 4));
592 break;
593 case EXTID_EXTT:
594 int flag = Byte.toUnsignedInt(extra[pos++]);
595 if ((flag & 0x1) != 0) {
596 e.mtime = unixToJavaTime(get32(extra, pos));
597 pos += 4;
598 }
599 break;
600 default: // unknown tag
601 }
602 off += (sz + 4);
603 }
604 }
605 if (e.mtime == -1) {
606 e.mtime = dosToJavaTime(getEntryTime(jzentry));
607 }
608 byte[] bcomm = getEntryBytes(jzentry, JZENTRY_COMMENT);
609 if (bcomm == null) {
610 e.comment = null;
611 } else {
612 if (!zc.isUTF8() && (e.flag & EFS) != 0) {
613 e.comment = zc.toStringUTF8(bcomm, bcomm.length);
614 } else {
615 e.comment = zc.toString(bcomm, bcomm.length);
616 }
617 }
618 return e;
619 }
620
621 private static native long getNextEntry(long jzfile, int i);
622
623 /**
624 * Returns the number of entries in the ZIP file.
625 * @return the number of entries in the ZIP file
626 * @throws IllegalStateException if the zip file has been closed
627 */
|
1 /*
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
550 public Stream<? extends ZipEntry> stream() {
551 return StreamSupport.stream(Spliterators.spliterator(
552 new ZipEntryIterator(), size(),
553 Spliterator.ORDERED | Spliterator.DISTINCT |
554 Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
555 }
556
557 private ZipEntry getZipEntry(String name, long jzentry) {
558 ZipEntry e = new ZipEntry();
559 e.flag = getEntryFlag(jzentry); // get the flag first
560 if (name != null) {
561 e.name = name;
562 } else {
563 byte[] bname = getEntryBytes(jzentry, JZENTRY_NAME);
564 if (!zc.isUTF8() && (e.flag & EFS) != 0) {
565 e.name = zc.toStringUTF8(bname, bname.length);
566 } else {
567 e.name = zc.toString(bname, bname.length);
568 }
569 }
570 e.time = dosToJavaTime(getEntryTime(jzentry));
571 e.crc = getEntryCrc(jzentry);
572 e.size = getEntrySize(jzentry);
573 e.csize = getEntryCSize(jzentry);
574 e.method = getEntryMethod(jzentry);
575 e.setExtra0(getEntryBytes(jzentry, JZENTRY_EXTRA), false);
576 byte[] bcomm = getEntryBytes(jzentry, JZENTRY_COMMENT);
577 if (bcomm == null) {
578 e.comment = null;
579 } else {
580 if (!zc.isUTF8() && (e.flag & EFS) != 0) {
581 e.comment = zc.toStringUTF8(bcomm, bcomm.length);
582 } else {
583 e.comment = zc.toString(bcomm, bcomm.length);
584 }
585 }
586 return e;
587 }
588
589 private static native long getNextEntry(long jzfile, int i);
590
591 /**
592 * Returns the number of entries in the ZIP file.
593 * @return the number of entries in the ZIP file
594 * @throws IllegalStateException if the zip file has been closed
595 */
|