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-codec.git
The following commit(s) were added to refs/heads/master by this push: new 73813dcf Use try-with-resources 73813dcf is described below commit 73813dcfdd17069df2db8939b701416c5b037b9d Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Jan 8 08:26:23 2024 -0500 Use try-with-resources --- .../codec/binary/Base64InputStreamTest.java | 42 ++++++++++------------ 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java index 4e45ad9a..7e154110 100644 --- a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java +++ b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java @@ -245,35 +245,32 @@ public class Base64InputStreamTest { * Usually signifies a bug in the Base64 commons-codec implementation. */ private void testByteByByte(final byte[] encoded, final byte[] decoded, final int chunkSize, final byte[] separator) throws Exception { - - // Start with encode. - InputStream in; - in = new Base64InputStream(new ByteArrayInputStream(decoded), true, chunkSize, separator); byte[] output = new byte[encoded.length]; - for (int i = 0; i < output.length; i++) { - output[i] = (byte) in.read(); - } + // Start with encode. + try (InputStream in = new Base64InputStream(new ByteArrayInputStream(decoded), true, chunkSize, separator)) { + for (int i = 0; i < output.length; i++) { + output[i] = (byte) in.read(); + } - assertEquals(-1, in.read(), "EOF"); - assertEquals(-1, in.read(), "Still EOF"); - assertArrayEquals(encoded, output, "Streaming base64 encode"); + assertEquals(-1, in.read(), "EOF"); + assertEquals(-1, in.read(), "Still EOF"); + assertArrayEquals(encoded, output, "Streaming base64 encode"); - in.close(); - // Now let's try to decode. - in = new Base64InputStream(new ByteArrayInputStream(encoded)); - output = new byte[decoded.length]; - for (int i = 0; i < output.length; i++) { - output[i] = (byte) in.read(); } + // Now let's try to decode. + try (InputStream in = new Base64InputStream(new ByteArrayInputStream(encoded))) { + output = new byte[decoded.length]; + for (int i = 0; i < output.length; i++) { + output[i] = (byte) in.read(); + } - assertEquals(-1, in.read(), "EOF"); - assertEquals(-1, in.read(), "Still EOF"); - assertArrayEquals(decoded, output, "Streaming base64 decode"); - - in.close(); + assertEquals(-1, in.read(), "EOF"); + assertEquals(-1, in.read(), "Still EOF"); + assertArrayEquals(decoded, output, "Streaming base64 decode"); + } // I always wanted to do this! (wrap encoder with decoder etc.). - in = new ByteArrayInputStream(decoded); + InputStream in = new ByteArrayInputStream(decoded); for (int i = 0; i < 10; i++) { in = new Base64InputStream(in, true, chunkSize, separator); in = new Base64InputStream(in, false); @@ -286,7 +283,6 @@ public class Base64InputStreamTest { assertEquals(-1, in.read(), "EOF"); assertEquals(-1, in.read(), "Still EOF"); assertArrayEquals(decoded, output, "Streaming base64 wrap-wrap-wrap!"); - in.close(); } /**