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 67773252 Use try-with-resources 67773252 is described below commit 67773252f8c506c4d18ac6498a938059920d2545 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Nov 4 07:13:39 2023 -0400 Use try-with-resources --- .../apache/commons/compress/utils/IOUtilsTest.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java b/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java index c7a0efbe..a93236cf 100644 --- a/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java +++ b/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java @@ -40,22 +40,23 @@ public class IOUtilsTest { } private static void readFully(final byte[] source, final ByteBuffer b) throws IOException { - IOUtils.readFully(new SeekableInMemoryByteChannel(source), b); + try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(source)) { + IOUtils.readFully(channel, b); + } } private void skip(final StreamWrapper wrapper) throws Exception { - final ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 - }); - final InputStream sut = wrapper.wrap(in); - assertEquals(10, IOUtils.skip(sut, 10)); - assertEquals(11, sut.read()); + final ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }); + try (InputStream sut = wrapper.wrap(in)) { + assertEquals(10, IOUtils.skip(sut, 10)); + assertEquals(11, sut.read()); + } } @Test public void testCopyRangeDoesntCopyMoreThanAskedFor() throws IOException { try (ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }); - ByteArrayOutputStream out = new ByteArrayOutputStream()) { + ByteArrayOutputStream out = new ByteArrayOutputStream()) { assertEquals(3, IOUtils.copyRange(in, 3, out)); out.close(); assertArrayEquals(new byte[] { 1, 2, 3 }, out.toByteArray()); @@ -65,7 +66,7 @@ public class IOUtilsTest { @Test public void testCopyRangeStopsIfThereIsNothingToCopyAnymore() throws IOException { try (ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }); - ByteArrayOutputStream out = new ByteArrayOutputStream()) { + ByteArrayOutputStream out = new ByteArrayOutputStream()) { assertEquals(5, IOUtils.copyRange(in, 10, out)); out.close(); assertArrayEquals(new byte[] { 1, 2, 3, 4, 5 }, out.toByteArray()); @@ -75,7 +76,7 @@ public class IOUtilsTest { @Test public void testCopyRangeThrowsOnZeroBufferSize() { assertThrows(IllegalArgumentException.class, - () -> IOUtils.copyRange(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), 5, new ByteArrayOutputStream(), 0)); + () -> IOUtils.copyRange(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), 5, new ByteArrayOutputStream(), 0)); } @Test @@ -199,6 +200,7 @@ public class IOUtilsTest { public void testSkipUsingSkipAndRead() throws Exception { skip(toWrap -> new FilterInputStream(toWrap) { boolean skipped; + @Override public long skip(final long s) throws IOException { if (!skipped) {