You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/07/22 07:00:39 UTC

[11/50] commons-crypto git commit: Use try-with-resources.

Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/d3a77423
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/d3a77423
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/d3a77423

Branch: refs/heads/CRYPTO-1.0.0
Commit: d3a77423a3d54c83e2c6f1ef018b2ebb06b05f12
Parents: 0715c6c
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:20:11 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:20:11 2016 -0700

----------------------------------------------------------------------
 .../commons/crypto/examples/RandomExample.java       | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/d3a77423/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/examples/RandomExample.java b/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
index 5206049..5505ee5 100644
--- a/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
+++ b/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
@@ -40,17 +40,16 @@ public class RandomExample {
             CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
 
         // Gets the 'CryptoRandom' instance.
-        CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties);
+        try (CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties)) {
 
-        // Show the actual class (may be different from the one requested)
-        System.out.println(random.getClass().getCanonicalName());
+            // Show the actual class (may be different from the one requested)
+            System.out.println(random.getClass().getCanonicalName());
 
-        // Generate random bytes and places them into the byte arrays.
-        random.nextBytes(key);
-        random.nextBytes(iv);
+            // Generate random bytes and places them into the byte arrays.
+            random.nextBytes(key);
+            random.nextBytes(iv);
 
-        // Closes the CryptoRandom.
-        random.close();
+        }
 
         // Show the generated output
         System.out.println(Arrays.toString(key));