From cd024bb17b0e8a0d4ff8a7fb08eddf4a94b4635b Mon Sep 17 00:00:00 2001 From: ksrini Date: Mon, 28 Mar 2011 13:50:01 -0700 Subject: [PATCH] 7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem Reviewed-by: alanb --- test/tools/pack200/CommandLineTests.java | 4 +- test/tools/pack200/TimeStamp.java | 2 +- test/tools/pack200/Utils.java | 47 ++++-------------------- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/test/tools/pack200/CommandLineTests.java b/test/tools/pack200/CommandLineTests.java index fefefd2a8..74a1524fa 100644 --- a/test/tools/pack200/CommandLineTests.java +++ b/test/tools/pack200/CommandLineTests.java @@ -120,9 +120,9 @@ public class CommandLineTests { // make a backup copy for re-use File bakFile = new File(f.getName() + ".bak"); if (!bakFile.exists()) { // backup - Utils.copyFile(f.getAbsoluteFile(), bakFile.getAbsoluteFile()); + Utils.copyFile(f, bakFile); } else { // restore - Utils.copyFile(bakFile.getAbsoluteFile(), f.getAbsoluteFile()); + Utils.copyFile(bakFile, f); } cmdsList.clear(); cmdsList.add(Utils.getPack200Cmd()); diff --git a/test/tools/pack200/TimeStamp.java b/test/tools/pack200/TimeStamp.java index 3d099e214..aa82fbb4e 100644 --- a/test/tools/pack200/TimeStamp.java +++ b/test/tools/pack200/TimeStamp.java @@ -56,7 +56,7 @@ public class TimeStamp { // make a local copy of our test file File srcFile = Utils.locateJar("golden.jar"); File goldenFile = new File("golden.jar"); - Utils.copyFile(srcFile, goldenFile.getAbsoluteFile()); + Utils.copyFile(srcFile, goldenFile); JarFile goldenJarFile = new JarFile(goldenFile); File packFile = new File("golden.pack"); diff --git a/test/tools/pack200/Utils.java b/test/tools/pack200/Utils.java index 5cf7663d2..53c1a1baa 100644 --- a/test/tools/pack200/Utils.java +++ b/test/tools/pack200/Utils.java @@ -21,18 +21,18 @@ * questions. */ +import java.nio.file.Path; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.File; import java.io.FileFilter; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; -import java.nio.channels.FileChannel; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -44,6 +44,8 @@ import java.util.jar.Pack200; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import static java.nio.file.StandardCopyOption.*; + /** * * @author ksrini @@ -180,45 +182,12 @@ class Utils { } }; - private static void setFileAttributes(File src, File dst) throws IOException { - dst.setExecutable(src.canExecute()); - dst.setReadable(src.canRead()); - dst.setWritable(src.canWrite()); - dst.setLastModified(src.lastModified()); - } - static void copyFile(File src, File dst) throws IOException { - if (src.isDirectory()) { - dst.mkdirs(); - setFileAttributes(src, dst); - return; - } else { - File baseDirFile = dst.getParentFile(); - if (!baseDirFile.exists()) { - baseDirFile.mkdirs(); - } - } - FileInputStream in = null; - FileOutputStream out = null; - FileChannel srcChannel = null; - FileChannel dstChannel = null; - try { - in = new FileInputStream(src); - out = new FileOutputStream(dst); - srcChannel = in.getChannel(); - dstChannel = out.getChannel(); - - long retval = srcChannel.transferTo(0, src.length(), dstChannel); - if (src.length() != dst.length()) { - throw new IOException("file copy failed for " + src); - } - } finally { - close(srcChannel); - close(dstChannel); - close(in); - close(out); + Path parent = dst.toPath().getParent(); + if (parent != null) { + Files.createDirectories(parent); } - setFileAttributes(src, dst); + Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); } static String baseName(File file, String extension) { -- GitLab