jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1783512 - /jmeter/trunk/src/core/org/apache/jmeter/util/SSLManager.java
Date Sat, 18 Feb 2017 11:10:20 GMT
Author: fschumacher
Date: Sat Feb 18 11:10:20 2017
New Revision: 1783512

URL: http://svn.apache.org/viewvc?rev=1783512&view=rev
Log:
Use try-with statement to close all streams.

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/SSLManager.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/SSLManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/SSLManager.java?rev=1783512&r1=1783511&r2=1783512&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/SSLManager.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/SSLManager.java Sat Feb 18 11:10:20 2017
@@ -124,15 +124,19 @@ public abstract class SSLManager {
                 this.keyStore = null;
                 throw new RuntimeException("Could not create keystore: "+e.getMessage(),
e);
             }
-            InputStream fileInputStream = null;
+
             try {
                 File initStore = new File(fileName);
 
                 if (fileName.length() >0 && initStore.exists()) {
-                    fileInputStream = new BufferedInputStream(new FileInputStream(initStore));
-                    this.keyStore.load(fileInputStream, getPassword());
-                    if (log.isInfoEnabled()) {
-                        log.info("Total of {} aliases loaded OK from keystore", keyStore.getAliasCount());
+                    try (InputStream fis = new FileInputStream(initStore);
+                            InputStream fileInputStream = new BufferedInputStream(fis)) {
+                        this.keyStore.load(fileInputStream, getPassword());
+                        if (log.isInfoEnabled()) {
+                            log.info(
+                                    "Total of {} aliases loaded OK from keystore",
+                                    keyStore.getAliasCount());
+                        }
                     }
                 } else {
                     log.warn("Keystore file not found, loading empty keystore");
@@ -141,8 +145,6 @@ public abstract class SSLManager {
                 }
             } catch (Exception e) {
                 log.error("Problem loading keystore: {}", e.getMessage(), e);
-            } finally {
-                JOrphanUtils.closeQuietly(fileInputStream);
             }
 
             if (log.isDebugEnabled()) {
@@ -217,22 +219,21 @@ public abstract class SSLManager {
                 throw new RuntimeException("Problem creating truststore: "+e.getMessage(),
e);
             }
 
-            InputStream fileInputStream = null;
             try {
                 File initStore = new File(fileName);
 
                 if (initStore.exists()) {
-                    fileInputStream = new BufferedInputStream(new FileInputStream(initStore));
-                    this.trustStore.load(fileInputStream, null);
-                    log.info("Truststore loaded OK from file");
+                    try (InputStream fis = new FileInputStream(initStore);
+                            InputStream fileInputStream = new BufferedInputStream(fis)) {
+                        this.trustStore.load(fileInputStream, null);
+                        log.info("Truststore loaded OK from file");
+                    }
                 } else {
                     log.info("Truststore file not found, loading empty truststore");
                     this.trustStore.load(null, null);
                 }
             } catch (Exception e) {
                 throw new RuntimeException("Can't load TrustStore: " + e.getMessage(), e);
-            } finally {
-                JOrphanUtils.closeQuietly(fileInputStream);
             }
         }
 



Mime
View raw message