jdk/src/share/classes/java/util/zip/ZipFile.java
changeset 18223 35a5c2462991
parent 9676 5663e62f8d7e
child 18251 3743160a4cb8
equal deleted inserted replaced
18222:2b50015e08db 18223:35a5c2462991
    52  *
    52  *
    53  * @author      David Connelly
    53  * @author      David Connelly
    54  */
    54  */
    55 public
    55 public
    56 class ZipFile implements ZipConstants, Closeable {
    56 class ZipFile implements ZipConstants, Closeable {
    57     private long jzfile;  // address of jzfile data
    57     private long jzfile;           // address of jzfile data
    58     private String name;  // zip file name
    58     private final String name;     // zip file name
    59     private int total;    // total number of entries
    59     private final int total;       // total number of entries
       
    60     private final boolean locsig;  // if zip file starts with LOCSIG (usually true)
    60     private volatile boolean closeRequested = false;
    61     private volatile boolean closeRequested = false;
    61 
    62 
    62     private static final int STORED = ZipEntry.STORED;
    63     private static final int STORED = ZipEntry.STORED;
    63     private static final int DEFLATED = ZipEntry.DEFLATED;
    64     private static final int DEFLATED = ZipEntry.DEFLATED;
    64 
    65 
   214         jzfile = open(name, mode, file.lastModified(), usemmap);
   215         jzfile = open(name, mode, file.lastModified(), usemmap);
   215         sun.misc.PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
   216         sun.misc.PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
   216         sun.misc.PerfCounter.getZipFileCount().increment();
   217         sun.misc.PerfCounter.getZipFileCount().increment();
   217         this.name = name;
   218         this.name = name;
   218         this.total = getTotal(jzfile);
   219         this.total = getTotal(jzfile);
       
   220         this.locsig = startsWithLOC(jzfile);
   219     }
   221     }
   220 
   222 
   221     /**
   223     /**
   222      * Opens a zip file for reading.
   224      * Opens a zip file for reading.
   223      *
   225      *
   735         protected void finalize() {
   737         protected void finalize() {
   736             close();
   738             close();
   737         }
   739         }
   738     }
   740     }
   739 
   741 
       
   742     static {
       
   743         sun.misc.SharedSecrets.setJavaUtilZipFileAccess(
       
   744             new sun.misc.JavaUtilZipFileAccess() {
       
   745                 public boolean startsWithLocHeader(ZipFile zip) {
       
   746                     return zip.startsWithLocHeader();
       
   747                 }
       
   748              }
       
   749         );
       
   750     }
       
   751 
       
   752     /**
       
   753      * Returns {@code true} if, and only if, the zip file begins with {@code
       
   754      * LOCSIG}.
       
   755      */
       
   756     private boolean startsWithLocHeader() {
       
   757         return locsig;
       
   758     }
   740 
   759 
   741     private static native long open(String name, int mode, long lastModified,
   760     private static native long open(String name, int mode, long lastModified,
   742                                     boolean usemmap) throws IOException;
   761                                     boolean usemmap) throws IOException;
   743     private static native int getTotal(long jzfile);
   762     private static native int getTotal(long jzfile);
       
   763     private static native boolean startsWithLOC(long jzfile);
   744     private static native int read(long jzfile, long jzentry,
   764     private static native int read(long jzfile, long jzentry,
   745                                    long pos, byte[] b, int off, int len);
   765                                    long pos, byte[] b, int off, int len);
   746 
   766 
   747     // access to the native zentry object
   767     // access to the native zentry object
   748     private static native long getEntryTime(long jzentry);
   768     private static native long getEntryTime(long jzentry);