< prev index next >

src/java.base/share/classes/java/util/zip/ZipFile.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2018, 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


 656         if (name == null || bname.length != nlen) {
 657             // to use the entry name stored in cen, if the passed in name is
 658             // (1) null, invoked from iterator, or
 659             // (2) not equal to the name stored, a slash is appended during
 660             // getEntryPos() search.
 661             if (!zc.isUTF8() && (flag & USE_UTF8) != 0) {
 662                 name = zc.toStringUTF8(cen, pos + CENHDR, nlen);
 663             } else {
 664                 name = zc.toString(cen, pos + CENHDR, nlen);
 665             }
 666         }
 667         ZipEntry e = func.apply(name);    //ZipEntry e = new ZipEntry(name);
 668         e.flag = flag;
 669         e.xdostime = CENTIM(cen, pos);
 670         e.crc = CENCRC(cen, pos);
 671         e.size = CENLEN(cen, pos);
 672         e.csize = CENSIZ(cen, pos);
 673         e.method = CENHOW(cen, pos);
 674         if (elen != 0) {
 675             int start = pos + CENHDR + nlen;
 676             e.setExtra0(Arrays.copyOfRange(cen, start, start + elen), true);
 677         }
 678         if (clen != 0) {
 679             int start = pos + CENHDR + nlen + elen;
 680             if (!zc.isUTF8() && (flag & USE_UTF8) != 0) {
 681                 e.comment = zc.toStringUTF8(cen, start, clen);
 682             } else {
 683                 e.comment = zc.toString(cen, start, clen);
 684             }
 685         }
 686         lastEntryName = e.name;
 687         lastEntryPos = pos;
 688         return e;
 689     }
 690 
 691     /**
 692      * Returns the number of entries in the ZIP file.
 693      *
 694      * @return the number of entries in the ZIP file
 695      * @throws IllegalStateException if the zip file has been closed
 696      */


   1 /*
   2  * Copyright (c) 1995, 2019, 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


 656         if (name == null || bname.length != nlen) {
 657             // to use the entry name stored in cen, if the passed in name is
 658             // (1) null, invoked from iterator, or
 659             // (2) not equal to the name stored, a slash is appended during
 660             // getEntryPos() search.
 661             if (!zc.isUTF8() && (flag & USE_UTF8) != 0) {
 662                 name = zc.toStringUTF8(cen, pos + CENHDR, nlen);
 663             } else {
 664                 name = zc.toString(cen, pos + CENHDR, nlen);
 665             }
 666         }
 667         ZipEntry e = func.apply(name);    //ZipEntry e = new ZipEntry(name);
 668         e.flag = flag;
 669         e.xdostime = CENTIM(cen, pos);
 670         e.crc = CENCRC(cen, pos);
 671         e.size = CENLEN(cen, pos);
 672         e.csize = CENSIZ(cen, pos);
 673         e.method = CENHOW(cen, pos);
 674         if (elen != 0) {
 675             int start = pos + CENHDR + nlen;
 676             e.setExtra0(Arrays.copyOfRange(cen, start, start + elen), true, false);
 677         }
 678         if (clen != 0) {
 679             int start = pos + CENHDR + nlen + elen;
 680             if (!zc.isUTF8() && (flag & USE_UTF8) != 0) {
 681                 e.comment = zc.toStringUTF8(cen, start, clen);
 682             } else {
 683                 e.comment = zc.toString(cen, start, clen);
 684             }
 685         }
 686         lastEntryName = e.name;
 687         lastEntryPos = pos;
 688         return e;
 689     }
 690 
 691     /**
 692      * Returns the number of entries in the ZIP file.
 693      *
 694      * @return the number of entries in the ZIP file
 695      * @throws IllegalStateException if the zip file has been closed
 696      */


< prev index next >