8157996: Unneeded import in lib/testlibrary/jdk/testlibrary/SimpleSSLContext.java
authorshurailine
Fri, 27 May 2016 14:26:58 -0700
changeset 38586 a4c2c26a296a
parent 38585 4e6b93b00caa
child 38587 512822cb2cfe
8157996: Unneeded import in lib/testlibrary/jdk/testlibrary/SimpleSSLContext.java Reviewed-by: mchung, chegar Contributed-by: alexandre.iline@oracle.com
jdk/test/lib/testlibrary/jdk/testlibrary/SimpleSSLContext.java
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/SimpleSSLContext.java	Fri May 27 14:24:38 2016 -0700
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/SimpleSSLContext.java	Fri May 27 14:26:58 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -23,8 +23,6 @@
 
 package jdk.testlibrary;
 
-import com.sun.net.httpserver.*;
-
 import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
@@ -54,7 +52,7 @@
      * loads default keystore from SimpleSSLContext
      * source directory
      */
-    public SimpleSSLContext () throws IOException {
+    public SimpleSSLContext() throws IOException {
         String paths = System.getProperty("test.src.path");
         StringTokenizer st = new StringTokenizer(paths, File.pathSeparator);
         boolean securityExceptions = false;
@@ -63,8 +61,10 @@
             try {
                 File f = new File(path, "jdk/testlibrary/testkeys");
                 if (f.exists()) {
-                    init (new FileInputStream(f));
-                    return;
+                    try (FileInputStream fis = new FileInputStream(f)) {
+                        init(fis);
+                        return;
+                    }
                 }
             } catch (SecurityException e) {
                 // catch and ignore because permission only required
@@ -80,13 +80,14 @@
     /**
      * loads default keystore from given directory
      */
-    public SimpleSSLContext (String dir) throws IOException {
+    public SimpleSSLContext(String dir) throws IOException {
         String file = dir+"/testkeys";
-        FileInputStream fis = new FileInputStream(file);
-        init(fis);
+        try (FileInputStream fis = new FileInputStream(file)) {
+            init(fis);
+        }
     }
 
-    private void init (InputStream i) throws IOException {
+    private void init(InputStream i) throws IOException {
         try {
             char[] passphrase = "passphrase".toCharArray();
             KeyStore ks = KeyStore.getInstance("JKS");
@@ -98,22 +99,22 @@
             TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
             tmf.init(ks);
 
-            ssl = SSLContext.getInstance ("TLS");
+            ssl = SSLContext.getInstance("TLS");
             ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
         } catch (KeyManagementException e) {
-            throw new RuntimeException (e.getMessage());
+            throw new RuntimeException(e.getMessage());
         } catch (KeyStoreException e) {
-            throw new RuntimeException (e.getMessage());
+            throw new RuntimeException(e.getMessage());
         } catch (UnrecoverableKeyException e) {
-            throw new RuntimeException (e.getMessage());
+            throw new RuntimeException(e.getMessage());
         } catch (CertificateException e) {
-            throw new RuntimeException (e.getMessage());
+            throw new RuntimeException(e.getMessage());
         } catch (NoSuchAlgorithmException e) {
-            throw new RuntimeException (e.getMessage());
+            throw new RuntimeException(e.getMessage());
         }
     }
 
-    public SSLContext get () {
+    public SSLContext get() {
         return ssl;
     }
 }