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

commit c5c0dbe8fe456b3e9449639e72b144c2a9156303
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Aug 29 08:24:52 2023 -0400

    Use try-with-resources
---
 .../codec/binary/Base32OutputStreamTest.java       | 42 +++++++++++-----------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java 
b/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java
index 6a561160..8cb10449 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java
@@ -181,23 +181,23 @@ public class Base32OutputStreamTest {
 
         // Start with encode.
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-        OutputStream out = new Base32OutputStream(byteOut, true, chunkSize, 
separator);
-        out.write(decoded);
-        out.close();
+        try (OutputStream out = new Base32OutputStream(byteOut, true, 
chunkSize, separator)) {
+            out.write(decoded);
+        }
         byte[] output = byteOut.toByteArray();
         assertArrayEquals(encoded, output, "Streaming chunked Base32 encode");
 
         // Now let's try to decode.
         byteOut = new ByteArrayOutputStream();
-        out = new Base32OutputStream(byteOut, false);
-        out.write(encoded);
-        out.close();
+        try (OutputStream out = new Base32OutputStream(byteOut, false)) {
+            out.write(encoded);
+        }
         output = byteOut.toByteArray();
         assertArrayEquals(decoded, output, "Streaming chunked Base32 decode");
 
         // I always wanted to do this! (wrap encoder with decoder etc.).
         byteOut = new ByteArrayOutputStream();
-        out = byteOut;
+        OutputStream out = byteOut;
         for (int i = 0; i < 10; i++) {
             out = new Base32OutputStream(out, false);
             out = new Base32OutputStream(out, true, chunkSize, separator);
@@ -231,38 +231,38 @@ public class Base32OutputStreamTest {
 
         // Start with encode.
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-        OutputStream out = new Base32OutputStream(byteOut, true, chunkSize, 
separator);
-        for (final byte element : decoded) {
-            out.write(element);
+        try (OutputStream out = new Base32OutputStream(byteOut, true, 
chunkSize, separator)) {
+            for (final byte element : decoded) {
+                out.write(element);
+            }
         }
-        out.close();
         byte[] output = byteOut.toByteArray();
         assertArrayEquals(encoded, output, "Streaming byte-by-byte Base32 
encode");
 
         // Now let's try to decode.
         byteOut = new ByteArrayOutputStream();
-        out = new Base32OutputStream(byteOut, false);
-        for (final byte element : encoded) {
-            out.write(element);
+        try (OutputStream out = new Base32OutputStream(byteOut, false)) {
+            for (final byte element : encoded) {
+                out.write(element);
+            }
         }
-        out.close();
         output = byteOut.toByteArray();
         assertArrayEquals(decoded, output, "Streaming byte-by-byte Base32 
decode");
 
         // Now let's try to decode with tonnes of flushes.
         byteOut = new ByteArrayOutputStream();
-        out = new Base32OutputStream(byteOut, false);
-        for (final byte element : encoded) {
-            out.write(element);
-            out.flush();
+        try (OutputStream out = new Base32OutputStream(byteOut, false)) {
+            for (final byte element : encoded) {
+                out.write(element);
+                out.flush();
+            }
         }
-        out.close();
         output = byteOut.toByteArray();
         assertArrayEquals(decoded, output, "Streaming byte-by-byte flush() 
Base32 decode");
 
         // I always wanted to do this! (wrap encoder with decoder etc.).
         byteOut = new ByteArrayOutputStream();
-        out = byteOut;
+        OutputStream out = byteOut;
         for (int i = 0; i < 10; i++) {
             out = new Base32OutputStream(out, false);
             out = new Base32OutputStream(out, true, chunkSize, separator);

Reply via email to