jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
changeset 38466 4bcf5f2bb351
parent 38375 5df893ca926c
child 38467 172e0c9007a6
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java	Mon May 23 12:57:40 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java	Mon May 23 12:53:56 2016 -0700
@@ -54,6 +54,8 @@
 import java.util.stream.StreamSupport;
 import jdk.internal.misc.JavaUtilZipFileAccess;
 import jdk.internal.misc.SharedSecrets;
+import jdk.internal.misc.JavaIORandomAccessFileAccess;
+import jdk.internal.misc.VM;
 import jdk.internal.perf.PerfCounter;
 
 import static java.util.zip.ZipConstants.*;
@@ -805,19 +807,6 @@
         }
     }
 
-    static {
-        SharedSecrets.setJavaUtilZipFileAccess(
-            new JavaUtilZipFileAccess() {
-                public boolean startsWithLocHeader(ZipFile zip) {
-                    return zip.zsrc.startsWithLoc;
-                }
-                public String[] getMetaInfEntryNames(ZipFile zip) {
-                    return zip.getMetaInfEntryNames();
-                }
-             }
-        );
-    }
-
     /**
      * Returns an array of strings representing the names of all entries
      * that begin with "META-INF/" (case ignored). This method is used
@@ -842,6 +831,21 @@
         }
     }
 
+    private static boolean isWindows;
+    static {
+        SharedSecrets.setJavaUtilZipFileAccess(
+            new JavaUtilZipFileAccess() {
+                public boolean startsWithLocHeader(ZipFile zip) {
+                    return zip.zsrc.startsWithLoc;
+                }
+                public String[] getMetaInfEntryNames(ZipFile zip) {
+                    return zip.getMetaInfEntryNames();
+                }
+             }
+        );
+        isWindows = VM.getSavedProperty("os.name").contains("Windows");
+    }
+
     private static class Source {
         private final Key key;               // the key in files
         private int refs = 1;
@@ -956,9 +960,16 @@
 
         private Source(Key key, boolean toDelete) throws IOException {
             this.key = key;
-            this.zfile = new RandomAccessFile(key.file, "r");
             if (toDelete) {
-                key.file.delete();
+                if (isWindows) {
+                    this.zfile = SharedSecrets.getJavaIORandomAccessFileAccess()
+                                              .openAndDelete(key.file, "r");
+                } else {
+                    this.zfile = new RandomAccessFile(key.file, "r");
+                    key.file.delete();
+                }
+            } else {
+                this.zfile = new RandomAccessFile(key.file, "r");
             }
             try {
                 initCEN(-1);