diff --git a/BUILDING.md b/BUILDING.md index 7e334d941ff..f3ece6ce747 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -31,11 +31,11 @@ Some tests are only run when specific profiles are enabled, these tests require a lot of disk space as they test behavior for very large archives. - mvn test -Prun-tarit + mvn test -Prun-tar-it runs tests for tar archives and requires more than 8GiB of disk space. - mvn test -Prun-zipit + mvn test -Prun-zip-it runs tests for zip archives that require up to 20 GiB of disk space. In addition the tests will run for a long time (more than ten diff --git a/pom.xml b/pom.xml index 26dc1976a7d..68beb271e24 100644 --- a/pom.xml +++ b/pom.xml @@ -434,7 +434,7 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj. - run-zipit + run-zip-it @@ -466,7 +466,7 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj. - run-tarit + run-tar-it diff --git a/src/main/java/org/apache/commons/compress/CompressFilterOutputStream.java b/src/main/java/org/apache/commons/compress/CompressFilterOutputStream.java index b61b07f27f9..f3e1bcd0cf2 100644 --- a/src/main/java/org/apache/commons/compress/CompressFilterOutputStream.java +++ b/src/main/java/org/apache/commons/compress/CompressFilterOutputStream.java @@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.concurrent.atomic.AtomicBoolean; /** * Abstracts classes that compress or archive an output stream. @@ -51,6 +52,11 @@ private static byte[] write(final OutputStream os, final String data, final Char return bytes; } + /** + * Whether this instance was successfully closed. + */ + private final AtomicBoolean closed = new AtomicBoolean(); + /** * Constructs a new instance without a backing {@link OutputStream}. *

@@ -71,6 +77,35 @@ public CompressFilterOutputStream(final T out) { super(out); } + /** + * Check to make sure that this stream has not been closed + * + * @throws IOException if the stream is already closed + */ + protected void checkOpen() throws IOException { + if (isClosed()) { + throw new IOException("Stream closed"); + } + } + + @Override + public void close() throws IOException { + if (closed.compareAndSet(false, true)) { + // don't propagate more than once. + super.close(); + } + } + + /** + * Tests whether this instance was successfully closed. + * + * @return whether this instance was successfully closed. + * @since 1.27.0 + */ + public boolean isClosed() { + return closed.get(); + } + /** * Gets the underlying output stream. * @@ -108,7 +143,7 @@ public long write(final Path path) throws IOException { * * @param data the data. * @return the ASCII bytes. - * @exception IOException if an I/O error occurs. + * @throws IOException if an I/O error occurs. * @see OutputStream#write(byte[]) */ public byte[] writeUsAscii(final String data) throws IOException { @@ -120,7 +155,7 @@ public byte[] writeUsAscii(final String data) throws IOException { * * @param data the data. * @return the ASCII bytes. - * @exception IOException if an I/O error occurs. + * @throws IOException if an I/O error occurs. * @see OutputStream#write(byte[]) */ public byte[] writeUsAsciiRaw(final String data) throws IOException { @@ -132,7 +167,7 @@ public byte[] writeUsAsciiRaw(final String data) throws IOException { * * @param data the data. * @return the ASCII bytes. - * @exception IOException if an I/O error occurs. + * @throws IOException if an I/O error occurs. * @see OutputStream#write(byte[]) */ public byte[] writeUtf8(final String data) throws IOException { diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java index 576d173f01f..d9ac8f3d8cb 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java @@ -60,11 +60,6 @@ public abstract class ArchiveOutputStream extends Compre /** Holds the number of bytes written to this stream. */ private long bytesWritten; - /** - * Whether this instance was successfully closed. - */ - private boolean closed; - /** * Whether this instance was successfully finished. */ @@ -118,24 +113,6 @@ protected void checkFinished() throws IOException { } } - /** - * Check to make sure that this stream has not been closed - * - * @throws IOException if the stream is already closed - * @since 1.27.0 - */ - protected void checkOpen() throws IOException { - if (isClosed()) { - throw new IOException("Stream closed"); - } - } - - @Override - public void close() throws IOException { - super.close(); - closed = true; - } - /** * Closes the archive entry, writing any trailer information that may be required. * @@ -229,16 +206,6 @@ public int getCount() { return (int) bytesWritten; } - /** - * Tests whether this instance was successfully closed. - * - * @return whether this instance was successfully closed. - * @since 1.27.0 - */ - public boolean isClosed() { - return closed; - } - /** * Tests whether this instance was successfully finished. * diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java index 8fe4792a4b8..1c5b4be4fd2 100644 --- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java @@ -23,7 +23,6 @@ import java.util.Arrays; import org.apache.commons.compress.compressors.CompressorOutputStream; -import org.apache.commons.io.IOUtils; /** * An output stream that compresses into the BZip2 format into another stream. @@ -398,8 +397,6 @@ private static void hbMakeCodeLengths(final byte[] len, final int[] freq, final private BlockSort blockSorter; - private volatile boolean closed; - /** * Constructs a new {@code BZip2CompressorOutputStream} with a blocksize of 900k. * @@ -475,19 +472,13 @@ private void bsW(final int n, final int v) throws IOException { this.bsLive = bsLiveShadow + n; } - private void checkClosed() throws IOException { - if (closed) { - throw new IOException("Stream closed"); - } - } - @Override public void close() throws IOException { - if (!closed) { + if (!isClosed()) { try { finish(); } finally { - IOUtils.close(out); + super.close(); } } } @@ -545,8 +536,7 @@ private void endCompression() throws IOException { } public void finish() throws IOException { - if (!closed) { - closed = true; + if (!isClosed()) { try { if (this.runLength > 0) { writeRun(); @@ -1167,7 +1157,7 @@ public void write(final byte[] buf, int offs, final int len) throws IOException if (offs + len > buf.length) { throw new IndexOutOfBoundsException("offs(" + offs + ") + len(" + len + ") > buf.length(" + buf.length + ")."); } - checkClosed(); + checkOpen(); for (final int hi = offs + len; offs < hi;) { write0(buf[offs++]); } @@ -1175,7 +1165,7 @@ public void write(final byte[] buf, int offs, final int len) throws IOException @Override public void write(final int b) throws IOException { - checkClosed(); + checkOpen(); write0(b); } diff --git a/src/main/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStream.java index fa539955030..90c5f0c8dd9 100644 --- a/src/main/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStream.java @@ -62,7 +62,7 @@ public DeflateCompressorOutputStream(final OutputStream outputStream, final Defl @Override public void close() throws IOException { try { - out.close(); + super.close(); } finally { deflater.end(); } diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java index 5fc64ed8d0d..d4e8bb0b6b6 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java @@ -53,9 +53,6 @@ public class GzipCompressorOutputStream extends CompressorOutputStreamCalling flush() *

@@ -53,9 +53,11 @@ public XZCompressorOutputStream(final OutputStream outputStream) throws IOExcept * Creates a new XZ compressor using the specified LZMA2 preset level. *

* The presets 0-3 are fast presets with medium compression. The presets 4-6 are fairly slow presets with high compression. The default preset is 6. + *

*

* The presets 7-9 are like the preset 6 but use bigger dictionaries and have higher compressor and decompressor memory requirements. Unless the * uncompressed size of the file exceeds 8 MiB, 16 MiB, or 32 MiB, it is waste of memory to use the presets 7, 8, or 9, respectively. + *

* * @param outputStream the stream to wrap * @param preset the preset diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java index d3e2d038274..d05289e5076 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java @@ -34,7 +34,7 @@ public class ArArchiveOutputStreamTest extends AbstractTest { @Test public void testLongFileNamesCauseExceptionByDefault() throws IOException { - ArArchiveOutputStream ref; + final ArArchiveOutputStream ref; try (ArArchiveOutputStream outputStream = new ArArchiveOutputStream(new ByteArrayOutputStream())) { ref = outputStream; final ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 0); diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java index 090211caf85..cf0044d1c1d 100644 --- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java @@ -34,7 +34,7 @@ public class CpioArchiveOutputStreamTest extends AbstractTest { public void testWriteOldBinary() throws Exception { final File file = getFile("test1.xml"); final File output = newTempFile("test.cpio"); - CpioArchiveOutputStream ref; + final CpioArchiveOutputStream ref; try (CpioArchiveOutputStream outputStream = new CpioArchiveOutputStream(Files.newOutputStream(output.toPath()), CpioConstants.FORMAT_OLD_BINARY)) { ref = outputStream; outputStream.putArchiveEntry(new CpioArchiveEntry(CpioConstants.FORMAT_OLD_BINARY, file, "test1.xml")); diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java index e2fdd3d69a7..6beaacf02c6 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java @@ -56,7 +56,7 @@ public class TarArchiveOutputStreamTest extends AbstractTest { private static byte[] createTarArchiveContainingOneDirectory(final String fileName, final Date modificationDate) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - TarArchiveOutputStream ref; + final TarArchiveOutputStream ref; try (TarArchiveOutputStream outputStream = new TarArchiveOutputStream(baos, 1024)) { ref = outputStream; outputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java index 28bb325f3ec..82b0e7137f7 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java @@ -35,7 +35,7 @@ public class ZipArchiveOutputStreamTest extends AbstractTempDirTest { @Test public void testFileBasics() throws IOException { - ZipArchiveOutputStream ref; + final ZipArchiveOutputStream ref; try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(createTempFile())) { ref = outputStream; assertTrue(outputStream.isSeekable()); diff --git a/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java b/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java index 48c71549a5b..05a154ac062 100644 --- a/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java +++ b/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java @@ -193,9 +193,11 @@ public void testOutputStreamMethods() throws Exception { final Map m = new HashMap<>(); m.put("foo", "bar"); try (OutputStream out = Files.newOutputStream(output.toPath()); - OutputStream os = new Pack200CompressorOutputStream(out, m)) { + Pack200CompressorOutputStream os = new Pack200CompressorOutputStream(out, m)) { os.write(1); os.write(new byte[] { 2, 3 }); + os.close(); + assertTrue(os.isClosed()); } } diff --git a/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java index 8372dfb225a..d5821279f90 100644 --- a/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -78,6 +79,7 @@ public void testReadOfLength0ShouldReturn0() throws Exception { bzipOut.write(rawData); bzipOut.flush(); bzipOut.close(); + assertTrue(bzipOut.isClosed()); baos.flush(); } diff --git a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java index 20c3ffdcf52..c57ca228901 100644 --- a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.java @@ -35,6 +35,8 @@ public void testCanReadASingleByteFlushAndFinish() throws IOException { cos.flush(); cos.finish(); assertTrue(bos.toByteArray().length > 0); + cos.close(); + assertTrue(cos.isClosed()); } } diff --git a/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java index ec31b0eef88..83cc78f9aa7 100644 --- a/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java @@ -143,6 +143,8 @@ public void testExtraSubfields(final int subFieldCount, final Integer payloadSiz try (OutputStream fos = Files.newOutputStream(targetFile); GzipCompressorOutputStream gos = new GzipCompressorOutputStream(fos, parameters)) { gos.write(tempSourceFile); + gos.close(); + assertTrue(gos.isClosed()); } try (GzipCompressorInputStream gis = new GzipCompressorInputStream(Files.newInputStream(targetFile))) { final ExtraField extra2 = gis.getMetaData().getExtraField(); diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java index 4f4dfb571ab..29dd4c37b10 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java @@ -52,15 +52,16 @@ public void canWriteBackReferenceFollowedByShortLiteralIfOffsetIsBigEnough() { private byte[] compress(final byte[] input, final int... lengthOfTrailers) throws IOException { try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - BlockLZ4CompressorOutputStream lo = new BlockLZ4CompressorOutputStream(baos)) { - lo.write(input); + BlockLZ4CompressorOutputStream outputStream = new BlockLZ4CompressorOutputStream(baos)) { + outputStream.write(input); for (int i = 0; i < lengthOfTrailers.length; i++) { final int lengthOfTrailer = lengthOfTrailers[i]; for (int j = 0; j < lengthOfTrailer; j++) { - lo.write(i + 1); + outputStream.write(i + 1); } } - lo.close(); + outputStream.close(); + assertTrue(outputStream.isClosed()); return baos.toByteArray(); } } diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java index fd05889cf4a..25573c0145d 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java @@ -46,6 +46,8 @@ public void testWriteByteArrayVsWriteByte() throws IOException { new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { compressor.write(bytes); compressor.finish(); + compressor.close(); + assertTrue(compressor.isClosed()); } final byte[] bulkOutput = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); @@ -55,6 +57,8 @@ public void testWriteByteArrayVsWriteByte() throws IOException { compressor.write(element); } compressor.finish(); + compressor.close(); + assertTrue(compressor.isClosed()); } assertTrue(Arrays.equals(bulkOutput, buffer.toByteArray())); } diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java index f7f6a6d2299..4f1d27cd645 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java @@ -19,6 +19,7 @@ package org.apache.commons.compress.compressors.lz4; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -83,6 +84,8 @@ private void roundTripTest(final String testFile, final FramedLZ4CompressorOutpu final ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (FramedLZ4CompressorOutputStream los = new FramedLZ4CompressorOutputStream(bos, params)) { IOUtils.copy(new ByteArrayInputStream(expected), los); + los.close(); + assertTrue(los.isClosed()); } try (FramedLZ4CompressorInputStream sis = new FramedLZ4CompressorInputStream(new ByteArrayInputStream(bos.toByteArray()))) { final byte[] actual = IOUtils.toByteArray(sis); diff --git a/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java index e6ab810d779..82e50204cef 100644 --- a/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java @@ -196,6 +196,8 @@ public void testWriteByteArrayVsWriteByte() throws IOException { try (FramedSnappyCompressorOutputStream compressor = new FramedSnappyCompressorOutputStream(buffer)) { compressor.write(bytes); compressor.finish(); + compressor.close(); + assertTrue(compressor.isClosed()); } final byte[] bulkOutput = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); @@ -204,6 +206,8 @@ public void testWriteByteArrayVsWriteByte() throws IOException { compressor.write(element); } compressor.finish(); + compressor.close(); + assertTrue(compressor.isClosed()); } assertArrayEquals(bulkOutput, buffer.toByteArray()); } diff --git a/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java index acb07f20832..98a4b2992f5 100644 --- a/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java @@ -19,6 +19,7 @@ package org.apache.commons.compress.compressors.snappy; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -58,6 +59,8 @@ private void roundTripTest(final Path input, final Parameters params) throws IOE try (OutputStream os = Files.newOutputStream(outputSz.toPath()); SnappyCompressorOutputStream sos = new SnappyCompressorOutputStream(os, Files.size(input), params)) { sos.write(input); + sos.close(); + assertTrue(sos.isClosed()); } try (SnappyCompressorInputStream sis = new SnappyCompressorInputStream(Files.newInputStream(outputSz.toPath()), params.getWindowSize())) { final byte[] expected = Files.readAllBytes(input); diff --git a/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java index 2c7ee2a7bdc..43245aaab73 100644 --- a/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/xz/XZCompressorOutputStreamTest.java @@ -19,6 +19,7 @@ package org.apache.commons.compress.compressors.xz; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -39,6 +40,8 @@ public void testWrite() throws IOException { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(4590); try (XZCompressorOutputStream xZCompressorOutputStream = new XZCompressorOutputStream(byteArrayOutputStream)) { xZCompressorOutputStream.write(4590); + xZCompressorOutputStream.close(); + assertTrue(xZCompressorOutputStream.isClosed()); } try (XZCompressorInputStream xZCompressorInputStream = new XZCompressorInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))) { diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java index 7fc0359b2b2..bae8903966c 100644 --- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java @@ -18,6 +18,7 @@ package org.apache.commons.compress.compressors.zstandard; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.FileOutputStream; @@ -34,6 +35,9 @@ import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; +/** + * Tests {@link ZstdCompressorOutputStream}. + */ public class ZstdRoundtripTest extends AbstractTest { private interface OutputStreamCreator { @@ -46,6 +50,8 @@ private void roundtrip(final OutputStreamCreator oc) throws IOException { try (FileOutputStream os = new FileOutputStream(output); ZstdCompressorOutputStream zos = oc.wrap(os)) { zos.write(input); + zos.close(); + assertTrue(zos.isClosed()); } try (ZstdCompressorInputStream zis = new ZstdCompressorInputStream(Files.newInputStream(output.toPath()))) { final byte[] expected = Files.readAllBytes(input);