< prev index next >

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

Print this page
rev 11478 : 8073497: Lazy conversion of ZipEntry time
Reviewed-by: sherman, plevart
   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


  29 import java.io.InputStream;
  30 import java.io.IOException;
  31 import java.io.EOFException;
  32 import java.io.File;
  33 import java.nio.charset.Charset;
  34 import java.nio.charset.StandardCharsets;
  35 import java.util.ArrayDeque;
  36 import java.util.Deque;
  37 import java.util.Enumeration;
  38 import java.util.HashMap;
  39 import java.util.Iterator;
  40 import java.util.Map;
  41 import java.util.NoSuchElementException;
  42 import java.util.Spliterator;
  43 import java.util.Spliterators;
  44 import java.util.WeakHashMap;
  45 import java.util.stream.Stream;
  46 import java.util.stream.StreamSupport;
  47 
  48 import static java.util.zip.ZipConstants64.*;
  49 import static java.util.zip.ZipUtils.*;
  50 
  51 /**
  52  * This class is used to read entries from a zip file.
  53  *
  54  * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  55  * or method in this class will cause a {@link NullPointerException} to be
  56  * thrown.
  57  *
  58  * @author      David Connelly
  59  */
  60 public
  61 class ZipFile implements ZipConstants, Closeable {
  62     private long jzfile;           // address of jzfile data
  63     private final String name;     // zip file name
  64     private final int total;       // total number of entries
  65     private final boolean locsig;  // if zip file starts with LOCSIG (usually true)
  66     private volatile boolean closeRequested = false;
  67 
  68     private static final int STORED = ZipEntry.STORED;
  69     private static final int DEFLATED = ZipEntry.DEFLATED;


 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 


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


  29 import java.io.InputStream;
  30 import java.io.IOException;
  31 import java.io.EOFException;
  32 import java.io.File;
  33 import java.nio.charset.Charset;
  34 import java.nio.charset.StandardCharsets;
  35 import java.util.ArrayDeque;
  36 import java.util.Deque;
  37 import java.util.Enumeration;
  38 import java.util.HashMap;
  39 import java.util.Iterator;
  40 import java.util.Map;
  41 import java.util.NoSuchElementException;
  42 import java.util.Spliterator;
  43 import java.util.Spliterators;
  44 import java.util.WeakHashMap;
  45 import java.util.stream.Stream;
  46 import java.util.stream.StreamSupport;
  47 
  48 import static java.util.zip.ZipConstants64.*;

  49 
  50 /**
  51  * This class is used to read entries from a zip file.
  52  *
  53  * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  54  * or method in this class will cause a {@link NullPointerException} to be
  55  * thrown.
  56  *
  57  * @author      David Connelly
  58  */
  59 public
  60 class ZipFile implements ZipConstants, Closeable {
  61     private long jzfile;           // address of jzfile data
  62     private final String name;     // zip file name
  63     private final int total;       // total number of entries
  64     private final boolean locsig;  // if zip file starts with LOCSIG (usually true)
  65     private volatile boolean closeRequested = false;
  66 
  67     private static final int STORED = ZipEntry.STORED;
  68     private static final int DEFLATED = ZipEntry.DEFLATED;


 549     public Stream<? extends ZipEntry> stream() {
 550         return StreamSupport.stream(Spliterators.spliterator(
 551                 new ZipEntryIterator(), size(),
 552                 Spliterator.ORDERED | Spliterator.DISTINCT |
 553                         Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
 554     }
 555 
 556     private ZipEntry getZipEntry(String name, long jzentry) {
 557         ZipEntry e = new ZipEntry();
 558         e.flag = getEntryFlag(jzentry);  // get the flag first
 559         if (name != null) {
 560             e.name = name;
 561         } else {
 562             byte[] bname = getEntryBytes(jzentry, JZENTRY_NAME);
 563             if (!zc.isUTF8() && (e.flag & EFS) != 0) {
 564                 e.name = zc.toStringUTF8(bname, bname.length);
 565             } else {
 566                 e.name = zc.toString(bname, bname.length);
 567             }
 568         }
 569         e.xdostime = getEntryTime(jzentry);
 570         e.crc = getEntryCrc(jzentry);
 571         e.size = getEntrySize(jzentry);
 572         e.csize = getEntryCSize(jzentry);
 573         e.method = getEntryMethod(jzentry);
 574         e.setExtra0(getEntryBytes(jzentry, JZENTRY_EXTRA), false);
 575         byte[] bcomm = getEntryBytes(jzentry, JZENTRY_COMMENT);
 576         if (bcomm == null) {
 577             e.comment = null;
 578         } else {
 579             if (!zc.isUTF8() && (e.flag & EFS) != 0) {
 580                 e.comment = zc.toStringUTF8(bcomm, bcomm.length);
 581             } else {
 582                 e.comment = zc.toString(bcomm, bcomm.length);
 583             }
 584         }
 585         return e;
 586     }
 587 
 588     private static native long getNextEntry(long jzfile, int i);
 589 


< prev index next >