This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
The following commit(s) were added to refs/heads/master by this push:
new 7c11f82 Refactor
org.apache.commons.crypto.utils.IoUtils.cleanup(Closeable...) to delegate array
elements to the new method
org.apache.commons.crypto.utils.IoUtils.closeQuietly(Closeable).
7c11f82 is described below
commit 7c11f8281349cae2bad76fbd53ee04b6d8c95107
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Aug 5 12:33:12 2020 -0400
Refactor org.apache.commons.crypto.utils.IoUtils.cleanup(Closeable...)
to delegate array elements to the new method
org.apache.commons.crypto.utils.IoUtils.closeQuietly(Closeable).
Use imports instead of fully qualified class names.
---
.../apache/commons/crypto/NativeCodeLoader.java | 2 +-
.../commons/crypto/random/OsCryptoRandom.java | 2 +-
.../org/apache/commons/crypto/utils/IoUtils.java | 27 ++++++++++++++++------
3 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
index e65d6ba..b4b6d9e 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -170,7 +170,7 @@ final class NativeCodeLoader {
writer.close();
- IoUtils.cleanup(reader);
+ IoUtils.closeQuietly(reader);
reader = null;
}
diff --git a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
index 2ca0eef..4eda9c5 100644
--- a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
@@ -131,7 +131,7 @@ class OsCryptoRandom extends Random implements CryptoRandom
{
@Override
synchronized public void close() {
if (stream != null) {
- IoUtils.cleanup(stream);
+ IoUtils.closeQuietly(stream);
stream = null;
}
}
diff --git a/src/main/java/org/apache/commons/crypto/utils/IoUtils.java
b/src/main/java/org/apache/commons/crypto/utils/IoUtils.java
index 13a3dd0..0ab3b5a 100644
--- a/src/main/java/org/apache/commons/crypto/utils/IoUtils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/IoUtils.java
@@ -17,6 +17,7 @@
*/
package org.apache.commons.crypto.utils;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@@ -86,13 +87,25 @@ public final class IoUtils {
*
* @param closeables the objects to close.
*/
- public static void cleanup(final java.io.Closeable... closeables) {
- for (final java.io.Closeable c : closeables) {
- if (c != null) {
- try {
- c.close();
- } catch (final IOException e) { // NOPMD
- }
+ public static void cleanup(final Closeable... closeables) {
+ if (closeables != null) {
+ for (final Closeable c : closeables) {
+ closeQuietly(c);
+ }
+ }
+ }
+
+ /**
+ * Closes the given {@link Closeable} quietly by ignoring IOException.
+ *
+ * @param closeable The resource to close.
+ * @since 1.1.0
+ */
+ public static void closeQuietly(final Closeable closeable) {
+ if (closeable != null) {
+ try {
+ closeable.close();
+ } catch (final IOException e) { // NOPMD
}
}
}