changeset 8474:fa38f8e0accd

8026233: test/sun/security/tools/keytool/StorePasswords.java needs to clean up files Reviewed-by: vinnie
author juh
date Thu, 17 Oct 2013 12:00:20 -0700
parents bc04f561bb78
children 64c0ac7cd936
files test/sun/security/tools/keytool/StorePasswords.java
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/tools/keytool/StorePasswords.java	Thu Oct 17 11:43:44 2013 -0700
+++ b/test/sun/security/tools/keytool/StorePasswords.java	Thu Oct 17 12:00:20 2013 -0700
@@ -77,6 +77,8 @@
         }
         System.out.println("\nStored " + storeCount + " user passwords, " +
             "recovered " + recoverCount + " user passwords");
+
+        new File(KEYSTORE).delete();
     }
 
     private static int store() throws Exception {
@@ -144,7 +146,9 @@
 
         // Store the PKCS#12 keystore
         System.out.println("Storing PKCS#12 keystore to: " + KEYSTORE);
-        keystore.store(new FileOutputStream(KEYSTORE), KEYSTORE_PWD);
+        try (FileOutputStream out = new FileOutputStream(KEYSTORE)) {
+            keystore.store(out, KEYSTORE_PWD);
+        }
 
         return count;
     }
@@ -154,7 +158,9 @@
         // Load the PKCS#12 keystore
         KeyStore keystore = KeyStore.getInstance("PKCS12");
         System.out.println("\nLoading PKCS#12 keystore from: " + KEYSTORE);
-        keystore.load(new FileInputStream(KEYSTORE), KEYSTORE_PWD);
+        try (FileInputStream in = new FileInputStream(KEYSTORE)) {
+            keystore.load(in, KEYSTORE_PWD);
+        }
 
         SecretKey key;
         SecretKeyFactory factory;