You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/08/29 22:44:36 UTC

[commons-compress] 01/03: Use try-with-resources

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

commit 95e67f0611897811168ce8f0e342204b3cb3cd0c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 29 17:29:33 2023 -0400

    Use try-with-resources
---
 .../deflate/DeflateCompressorInputStreamTest.java  | 30 ++++++++--------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
index 7a02bc7a..58a466bb 100644
--- a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
@@ -35,11 +35,9 @@ public class DeflateCompressorInputStreamTest {
     @Test
     public void availableShouldReturnNonZero() throws IOException {
         final File input = AbstractTestCase.getFile("bla.tar.deflatez");
-        try (InputStream is = Files.newInputStream(input.toPath())) {
-            final DeflateCompressorInputStream in =
-                    new DeflateCompressorInputStream(is);
+        try (InputStream is = Files.newInputStream(input.toPath());
+                DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
             assertTrue(in.available() > 0);
-            in.close();
         }
     }
 
@@ -47,49 +45,41 @@ public class DeflateCompressorInputStreamTest {
     public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
         final File input = AbstractTestCase.getFile("bla.tar.deflatez");
         final byte[] buf = new byte[2];
-        try (InputStream is = Files.newInputStream(input.toPath())) {
-            final DeflateCompressorInputStream in =
-                    new DeflateCompressorInputStream(is);
+        try (InputStream is = Files.newInputStream(input.toPath());
+                DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
             IOUtils.toByteArray(in);
             assertEquals(-1, in.read(buf));
             assertEquals(-1, in.read(buf));
-            in.close();
         }
     }
 
     @Test
     public void shouldBeAbleToSkipAByte() throws IOException {
         final File input = AbstractTestCase.getFile("bla.tar.deflatez");
-        try (InputStream is = Files.newInputStream(input.toPath())) {
-            final DeflateCompressorInputStream in =
-                    new DeflateCompressorInputStream(is);
+        try (InputStream is = Files.newInputStream(input.toPath());
+                DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
             assertEquals(1, in.skip(1));
-            in.close();
         }
     }
 
     @Test
     public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
         final File input = AbstractTestCase.getFile("bla.tar.deflatez");
-        try (InputStream is = Files.newInputStream(input.toPath())) {
-            final DeflateCompressorInputStream in =
-                    new DeflateCompressorInputStream(is);
+        try (InputStream is = Files.newInputStream(input.toPath());
+                DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
             IOUtils.toByteArray(in);
             assertEquals(-1, in.read());
             assertEquals(-1, in.read());
-            in.close();
         }
     }
 
     @Test
     public void singleByteReadWorksAsExpected() throws IOException {
         final File input = AbstractTestCase.getFile("bla.tar.deflatez");
-        try (InputStream is = Files.newInputStream(input.toPath())) {
-            final DeflateCompressorInputStream in =
-                    new DeflateCompressorInputStream(is);
+        try (InputStream is = Files.newInputStream(input.toPath());
+                DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
             // tar header starts with filename "test1.xml"
             assertEquals('t', in.read());
-            in.close();
         }
     }