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 2b00b7f8ee5476c5f9e42a58b20140394304c6a8 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Aug 29 11:05:01 2023 -0400 Use try-with-resources --- .../CompressorStreamFactoryRoundtripTest.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java index c73c9e0b..8f1500d8 100644 --- a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java @@ -53,19 +53,20 @@ public class CompressorStreamFactoryRoundtripTest { public void testCompressorStreamFactoryRoundtrip(final String compressorName) throws Exception { final CompressorStreamProvider factory = new CompressorStreamFactory(); final ByteArrayOutputStream compressedOs = new ByteArrayOutputStream(); - final CompressorOutputStream compressorOutputStream = factory.createCompressorOutputStream(compressorName, compressedOs); final String fixture = "The quick brown fox jumps over the lazy dog"; - compressorOutputStream.write(fixture.getBytes(UTF_8)); - compressorOutputStream.flush(); - compressorOutputStream.close(); + try (CompressorOutputStream compressorOutputStream = factory.createCompressorOutputStream(compressorName, compressedOs)) { + compressorOutputStream.write(fixture.getBytes(UTF_8)); + compressorOutputStream.flush(); + } final ByteArrayInputStream is = new ByteArrayInputStream(compressedOs.toByteArray()); - final CompressorInputStream compressorInputStream = factory.createCompressorInputStream(compressorName, is, false); - final ByteArrayOutputStream decompressedOs = new ByteArrayOutputStream(); - IOUtils.copy(compressorInputStream, decompressedOs); - compressorInputStream.close(); - decompressedOs.flush(); - decompressedOs.close(); - assertEquals(fixture, decompressedOs.toString("UTF-8")); + try (CompressorInputStream compressorInputStream = factory.createCompressorInputStream(compressorName, is, false)) { + final ByteArrayOutputStream decompressedOs = new ByteArrayOutputStream(); + IOUtils.copy(compressorInputStream, decompressedOs); + compressorInputStream.close(); + decompressedOs.flush(); + decompressedOs.close(); + assertEquals(fixture, decompressedOs.toString("UTF-8")); + } } }