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 eea47fac1a8adfac8de1f537dbe7c65f9e82e1ad Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Feb 5 10:30:59 2023 -0500 Use try-with-resources --- .../brotli/BrotliCompressorInputStreamTest.java | 36 ++++++++-------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java index 0371fe0e..72a0b254 100644 --- a/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java @@ -38,11 +38,9 @@ public class BrotliCompressorInputStreamTest extends AbstractTestCase { @Test public void availableShouldReturnZero() throws IOException { final File input = getFile("brotli.testdata.compressed"); - try (InputStream is = Files.newInputStream(input.toPath())) { - final BrotliCompressorInputStream in = - new BrotliCompressorInputStream(is); + try (InputStream is = Files.newInputStream(input.toPath()); + final BrotliCompressorInputStream in = new BrotliCompressorInputStream(is)) { assertEquals(0, in.available()); - in.close(); } } @@ -50,55 +48,47 @@ public class BrotliCompressorInputStreamTest extends AbstractTestCase { public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws IOException { final File input = getFile("brotli.testdata.compressed"); final byte[] buf = new byte[2]; - try (InputStream is = Files.newInputStream(input.toPath())) { - final BrotliCompressorInputStream in = - new BrotliCompressorInputStream(is); + try (InputStream is = Files.newInputStream(input.toPath()); + final BrotliCompressorInputStream in = new BrotliCompressorInputStream(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 = getFile("brotli.testdata.compressed"); - try (InputStream is = Files.newInputStream(input.toPath())) { - final BrotliCompressorInputStream in = - new BrotliCompressorInputStream(is); + try (InputStream is = Files.newInputStream(input.toPath()); + final BrotliCompressorInputStream in = new BrotliCompressorInputStream(is)) { assertEquals(1, in.skip(1)); - in.close(); } } @Test public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws IOException { final File input = getFile("brotli.testdata.compressed"); - try (InputStream is = Files.newInputStream(input.toPath())) { - final BrotliCompressorInputStream in = - new BrotliCompressorInputStream(is); + try (InputStream is = Files.newInputStream(input.toPath()); + final BrotliCompressorInputStream in = new BrotliCompressorInputStream(is)) { IOUtils.toByteArray(in); assertEquals(-1, in.read()); assertEquals(-1, in.read()); - in.close(); } } - @Test public void singleByteReadWorksAsExpected() throws IOException { final File input = getFile("brotli.testdata.compressed"); - try (InputStream is = Files.newInputStream(input.toPath())) { - final BrotliCompressorInputStream in = - new BrotliCompressorInputStream(is); - // starts with filename "XXX" + try (InputStream is = Files.newInputStream(input.toPath()); + final BrotliCompressorInputStream in = new BrotliCompressorInputStream(is)) { + // starts with filename "XXX" assertEquals('X', in.read()); - in.close(); } } /** * Test bridge works fine. + * * @throws IOException */ @Test @@ -106,7 +96,7 @@ public class BrotliCompressorInputStreamTest extends AbstractTestCase { final File input = getFile("brotli.testdata.compressed"); final File expected = getFile("brotli.testdata.uncompressed"); try (InputStream inputStream = Files.newInputStream(input.toPath()); - BrotliCompressorInputStream brotliInputStream = new BrotliCompressorInputStream(inputStream)) { + BrotliCompressorInputStream brotliInputStream = new BrotliCompressorInputStream(inputStream)) { final byte[] b = new byte[20]; IOUtils.read(expected, b); final ByteArrayOutputStream bos = new ByteArrayOutputStream();