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

Print this page

        

@@ -105,36 +105,19 @@
             }
         }
         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));
+        ensureIsFile(src);
+        try (FileOutputStream fos = new FileOutputStream(dst)) {
+            java.nio.file.Files.copy(src.toPath(), fos);
+        }
         dst.setLastModified(src.lastModified());
         if (src.canExecute())
             dst.setExecutable(true, false);
     }
 

@@ -187,13 +170,15 @@
                 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));
+                try (OutputStream out = newOutputStream(dst, deflate, dp)) {
+                    java.nio.file.Files.copy(src.toPath(), out);
             }
         }
+        }
     }
 
     public static void storeTree(File src, JarOutputStream dst, boolean deflate,
                                  Filter<File> filter)
         throws IOException