< prev index next >

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

Print this page
rev 11478 : 8073497: Lazy conversion of ZipEntry time
Reviewed-by: sherman, plevart
   1 /*
   2  * Copyright (c) 1996, 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


 286         flag = get16(tmpbuf, LOCFLG);
 287         // get the entry name and create the ZipEntry first
 288         int len = get16(tmpbuf, LOCNAM);
 289         int blen = b.length;
 290         if (len > blen) {
 291             do {
 292                 blen = blen * 2;
 293             } while (len > blen);
 294             b = new byte[blen];
 295         }
 296         readFully(b, 0, len);
 297         // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
 298         ZipEntry e = createZipEntry(((flag & EFS) != 0)
 299                                     ? zc.toStringUTF8(b, len)
 300                                     : zc.toString(b, len));
 301         // now get the remaining fields for the entry
 302         if ((flag & 1) == 1) {
 303             throw new ZipException("encrypted ZIP entry not supported");
 304         }
 305         e.method = get16(tmpbuf, LOCHOW);
 306         e.time = dosToJavaTime(get32(tmpbuf, LOCTIM));
 307         if ((flag & 8) == 8) {
 308             /* "Data Descriptor" present */
 309             if (e.method != DEFLATED) {
 310                 throw new ZipException(
 311                         "only DEFLATED entries can have EXT descriptor");
 312             }
 313         } else {
 314             e.crc = get32(tmpbuf, LOCCRC);
 315             e.csize = get32(tmpbuf, LOCSIZ);
 316             e.size = get32(tmpbuf, LOCLEN);
 317         }
 318         len = get16(tmpbuf, LOCEXT);
 319         if (len > 0) {
 320             byte[] extra = new byte[len];
 321             readFully(extra, 0, len);
 322             e.setExtra0(extra,
 323                         e.csize == ZIP64_MAGICVAL || e.size == ZIP64_MAGICVAL);
 324         }
 325         return e;
 326     }


   1 /*
   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.
   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


 286         flag = get16(tmpbuf, LOCFLG);
 287         // get the entry name and create the ZipEntry first
 288         int len = get16(tmpbuf, LOCNAM);
 289         int blen = b.length;
 290         if (len > blen) {
 291             do {
 292                 blen = blen * 2;
 293             } while (len > blen);
 294             b = new byte[blen];
 295         }
 296         readFully(b, 0, len);
 297         // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
 298         ZipEntry e = createZipEntry(((flag & EFS) != 0)
 299                                     ? zc.toStringUTF8(b, len)
 300                                     : zc.toString(b, len));
 301         // now get the remaining fields for the entry
 302         if ((flag & 1) == 1) {
 303             throw new ZipException("encrypted ZIP entry not supported");
 304         }
 305         e.method = get16(tmpbuf, LOCHOW);
 306         e.xdostime = get32(tmpbuf, LOCTIM);
 307         if ((flag & 8) == 8) {
 308             /* "Data Descriptor" present */
 309             if (e.method != DEFLATED) {
 310                 throw new ZipException(
 311                         "only DEFLATED entries can have EXT descriptor");
 312             }
 313         } else {
 314             e.crc = get32(tmpbuf, LOCCRC);
 315             e.csize = get32(tmpbuf, LOCSIZ);
 316             e.size = get32(tmpbuf, LOCLEN);
 317         }
 318         len = get16(tmpbuf, LOCEXT);
 319         if (len > 0) {
 320             byte[] extra = new byte[len];
 321             readFully(extra, 0, len);
 322             e.setExtra0(extra,
 323                         e.csize == ZIP64_MAGICVAL || e.size == ZIP64_MAGICVAL);
 324         }
 325         return e;
 326     }


< prev index next >