src/share/classes/org/openjdk/jigsaw/Files.java

Print this page

        

@@ -26,10 +26,12 @@
 package org.openjdk.jigsaw;
 
 import java.io.*;
 import java.util.jar.*;
 import java.util.zip.*;
+import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
 
 public final class Files {
 
     private Files() { }
 

@@ -105,39 +107,15 @@
             }
         }
         delete(dst);
     }
 
-    private static void copy(File src, OutputStream out)
-        throws IOException
-    {
-        ensureIsFile(src);
-        byte[] buf = new byte[8192];
-        FileInputStream in = new FileInputStream(src);
-        try {
-            try {
-                int n;
-                while ((n = in.read(buf)) > 0) {
-                    out.write(buf, 0, n);
-                }
-            } finally {
-                out.close();
-            }
-        } finally {
-            in.close();
-        }
-    }
-
     private static void copy(File src, File dst)
         throws IOException
     {
-        if (dst.exists())
-            ensureIsFile(dst);
-        copy(src, new FileOutputStream(dst));
-        dst.setLastModified(src.lastModified());
-        if (src.canExecute())
-            dst.setExecutable(true, false);
+        java.nio.file.Files.copy(src.toPath(), dst.toPath(),
+                                 COPY_ATTRIBUTES, REPLACE_EXISTING);
     }
 
     public static interface Filter<T> {
         public boolean accept(T x) throws IOException;
     }

@@ -187,13 +165,16 @@
                 continue;
             String dp = (dstPath == null) ? sls[i] : dstPath + "/" + sls[i];
             if (sf.isDirectory()) {
                 storeTree(sf, dst, deflate, filter, dp);
             } else {
-                copy(sf, newOutputStream(dst, deflate, dp));
+                ensureIsFile(sf);
+                try (OutputStream out = newOutputStream(dst, deflate, dp)) {
+                    java.nio.file.Files.copy(sf.toPath(), out);
             }
         }
+        }
     }
 
     public static void storeTree(File src, JarOutputStream dst, boolean deflate,
                                  Filter<File> filter)
         throws IOException