# HG changeset patch # User ksrini # Date 1301345401 25200 # Node ID e7036c25432423ac314c3bb4ab0b163a46ee54ae # Parent 1c23e333dd76abd4378bf79b8565f7e3c19c6378 7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem Reviewed-by: alanb diff -r 1c23e333dd76 -r e7036c254324 jdk/test/tools/pack200/CommandLineTests.java --- a/jdk/test/tools/pack200/CommandLineTests.java Mon Mar 28 18:04:17 2011 +0800 +++ b/jdk/test/tools/pack200/CommandLineTests.java Mon Mar 28 13:50:01 2011 -0700 @@ -120,9 +120,9 @@ // 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 -r 1c23e333dd76 -r e7036c254324 jdk/test/tools/pack200/TimeStamp.java --- a/jdk/test/tools/pack200/TimeStamp.java Mon Mar 28 18:04:17 2011 +0800 +++ b/jdk/test/tools/pack200/TimeStamp.java Mon Mar 28 13:50:01 2011 -0700 @@ -56,7 +56,7 @@ // 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 -r 1c23e333dd76 -r e7036c254324 jdk/test/tools/pack200/Utils.java --- a/jdk/test/tools/pack200/Utils.java Mon Mar 28 18:04:17 2011 +0800 +++ b/jdk/test/tools/pack200/Utils.java Mon Mar 28 13:50:01 2011 -0700 @@ -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.zip.ZipEntry; import java.util.zip.ZipFile; +import static java.nio.file.StandardCopyOption.*; + /** * * @author ksrini @@ -180,45 +182,12 @@ } }; - 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(); - } + Path parent = dst.toPath().getParent(); + if (parent != null) { + Files.createDirectories(parent); } - 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); - } - setFileAttributes(src, dst); + Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); } static String baseName(File file, String extension) {