8058856: tools/jar/LeadingGarbage.java, introduced in JDK-8058520, fails on Windows
authoralanb
Mon, 13 Oct 2014 18:16:29 +0100
changeset 27036 2bcadd860672
parent 27035 e1bd64d9b536
child 27037 5a6ef51923c4
8058856: tools/jar/LeadingGarbage.java, introduced in JDK-8058520, fails on Windows Reviewed-by: alanb, martin, sherman Contributed-by: amy.lu@oracle.com
jdk/test/tools/jar/LeadingGarbage.java
--- a/jdk/test/tools/jar/LeadingGarbage.java	Mon Oct 13 17:43:17 2014 +0100
+++ b/jdk/test/tools/jar/LeadingGarbage.java	Mon Oct 13 18:16:29 2014 +0100
@@ -30,7 +30,6 @@
 import java.io.OutputStream;
 import java.nio.file.Files;
 import java.nio.file.Paths;
-import sun.tools.jar.Main;
 
 import jdk.testlibrary.OutputAnalyzer;
 import jdk.testlibrary.ProcessTools;
@@ -54,9 +53,9 @@
     final File leadingGarbageZip = new File("leadingGarbage.zip");
 
     void createFile(File f) throws IOException {
-        OutputStream fos = new FileOutputStream(f);
-        fos.write(f.getName().getBytes("UTF-8"));
-        fos.close();
+        try (OutputStream fos = new FileOutputStream(f)) {
+            fos.write(f.getName().getBytes("UTF-8"));
+        }
     }
 
     void createFiles() throws IOException {
@@ -88,8 +87,9 @@
     void createZipWithLeadingGarbage() throws Throwable {
         createNormalZip();
         createFile(leadingGarbageZip);
-        OutputStream fos = new FileOutputStream(leadingGarbageZip, true);
-        Files.copy(normalZip.toPath(), fos);
+        try (OutputStream fos = new FileOutputStream(leadingGarbageZip, true)) {
+            Files.copy(normalZip.toPath(), fos);
+        }
         assertTrue(normalZip.length() < leadingGarbageZip.length());
         assertTrue(normalZip.delete());
     }
@@ -111,7 +111,7 @@
         a.shouldHaveExitValue(0);
         StringBuilder expected = new StringBuilder();
         for (File file : files)
-            expected.append(file.getName()).append('\n');
+            expected.append(file.getName()).append(System.lineSeparator());
         a.stdoutShouldMatch(expected.toString());
         a.stderrShouldMatch("\\A\\Z");
     }