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-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 94ff3f17 Use try-with-resources
94ff3f17 is described below

commit 94ff3f17ff4a020fedd2c63fcb7210bd48e23fbc
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Nov 4 06:34:03 2023 -0400

    Use try-with-resources
---
 .../compress/archivers/zip/ExplodeSupportTest.java | 29 ++++++++++------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
index 57f6a1b7..f864173d 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/zip/ExplodeSupportTest.java
@@ -47,10 +47,10 @@ public class ExplodeSupportTest {
 
             final ByteArrayOutputStream bout = new ByteArrayOutputStream();
             final CheckedOutputStream out = new CheckedOutputStream(bout, new 
CRC32());
-            IOUtils.copy(zip.getInputStream(entry), out);
-
-            out.flush();
-
+            try (InputStream inputStream = zip.getInputStream(entry)) {
+                IOUtils.copy(inputStream, out);
+                out.flush();
+            }
             assertEquals(entry.getCrc(), out.getChecksum().getValue(), 
"CRC32");
         }
     }
@@ -67,10 +67,10 @@ public class ExplodeSupportTest {
 
     @Test
     public void testConstructorThrowsExceptions() {
-        assertThrows(IllegalArgumentException.class, () -> new 
ExplodingInputStream(4095, 2, new ByteArrayInputStream(new byte[]{})),
+        assertThrows(IllegalArgumentException.class, () -> new 
ExplodingInputStream(4095, 2, new ByteArrayInputStream(new byte[] {})),
                 "should have failed with illegal argument exception");
 
-        assertThrows(IllegalArgumentException.class, () -> new 
ExplodingInputStream(4096, 4, new ByteArrayInputStream(new byte[]{})),
+        assertThrows(IllegalArgumentException.class, () -> new 
ExplodingInputStream(4096, 4, new ByteArrayInputStream(new byte[] {})),
                 "should have failed with illegal argument exception");
     }
 
@@ -90,16 +90,13 @@ public class ExplodeSupportTest {
             assertEquals(entryName, entry.getName(), "entry name");
             assertTrue(zin.canReadEntryData(entry), "entry can't be read");
             assertEquals(ZipMethod.IMPLODING.getCode(), entry.getMethod(), 
"method");
-
-            final InputStream bio = new BoundedInputStream(zin, 
entry.getSize());
-
-            final ByteArrayOutputStream bout = new ByteArrayOutputStream();
-            final CheckedOutputStream out = new CheckedOutputStream(bout, new 
CRC32());
-            IOUtils.copy(bio, out);
-
-            out.flush();
-
-            assertEquals(entry.getCrc(), out.getChecksum().getValue(), 
"CRC32");
+            try (InputStream bio = new BoundedInputStream(zin, 
entry.getSize())) {
+                final ByteArrayOutputStream bout = new ByteArrayOutputStream();
+                final CheckedOutputStream out = new CheckedOutputStream(bout, 
new CRC32());
+                IOUtils.copy(bio, out);
+                out.flush();
+                assertEquals(entry.getCrc(), out.getChecksum().getValue(), 
"CRC32");
+            }
         }
     }
 

Reply via email to