changeset 10865:a0ee740e01a5

8060432: tools/pack200/TestNormal.java fails on Windows with java.io.FileNotFoundException after JDK-8058854 Reviewed-by: ksrini Contributed-by: amy.lu@oracle.com
author ksrini
date Thu, 16 Oct 2014 19:27:46 -0700
parents cdcf2e599e42
children 3f42114ede90
files test/tools/pack200/TestNormal.java
diffstat 1 files changed, 5 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/pack200/TestNormal.java	Thu Oct 16 14:14:57 2014 -0700
+++ b/test/tools/pack200/TestNormal.java	Thu Oct 16 19:27:46 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,23 +42,15 @@
     public static void main(String args[]) throws Exception {
         Properties p = System.getProperties();
         String java_home = p.getProperty("test.jdk");
-        File testJar = new File("test.jar");
-        Utils.jar("cvf", testJar.getName(), Utils.TEST_CLS_DIR.getAbsolutePath());
-
-        File folder = new File("testdir");
-        if (folder.exists()) {
-            delete(folder);
-        }
-        folder.mkdir();
+        String testdir = Utils.TEST_CLS_DIR.getAbsolutePath();
 
         try {
-            extractJar(new JarFile(testJar), folder);
-            execJavaCommand(java_home, "jar cnf normalized.jar -C testdir .");
-            execJavaCommand(java_home, "jar cf original.jar -C testdir .");
+            execJavaCommand(java_home, "jar cnf normalized.jar -C " + testdir + " .");
+            execJavaCommand(java_home, "jar cf original.jar -C " + testdir + " .");
             execJavaCommand(java_home, "pack200 -r repacked.jar original.jar");
             compareJars(new JarFile("normalized.jar"), new JarFile("repacked.jar"));
         } finally {
-            String[] cleanupList = {"testdir", "normalized.jar", "original.jar", "repacked.jar"};
+            String[] cleanupList = {"normalized.jar", "original.jar", "repacked.jar"};
             for (String s : cleanupList) {
                 delete(new File(s));
             }
@@ -101,36 +93,6 @@
         }
     }
 
-    public static void extractJar(JarFile jf, File where) throws Exception {
-        for (JarEntry file : Collections.list(jf.entries())) {
-            File out = new File(where, file.getName());
-            if (file.isDirectory()) {
-                out.mkdirs();
-                continue;
-            }
-            File parent = out.getParentFile();
-            if (parent != null && !parent.exists()) {
-                parent.mkdirs();
-            }
-            InputStream is = null;
-            OutputStream os = null;
-            try {
-                is = jf.getInputStream(file);
-                os = new FileOutputStream(out);
-                while (is.available() > 0) {
-                    os.write(is.read());
-                }
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
-                if (os != null) {
-                    os.close();
-                }
-            }
-        }
-    }
-
     static void delete(File f) throws IOException {
         if (!f.exists()) {
             return;