You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Konrad Endruszkiewicz <ko...@gmail.com> on 2026/05/05 08:52:15 UTC

Apache Commons Compress - issue with working with ZSTD compression

Good day,

I have a following issue. In my project we are working with multiple ZSTD
archives and we need to decompress them from Java.

The archive.zip is more than 100MB in size.
Sample code that represents the issue:

        final var filePath = Path.of("archive.zip");

        for (var i = 0; i < 1000; i++) {
            var filesCount = 0;
            final var tempPath = Files.createTempDirectory("tmp");
            try (final var fis = Files.newInputStream(filePath)) {
                final var zipInputStream = new ZipArchiveInputStream(fis);
                ZipArchiveEntry entry;
                while ((entry = zipInputStream.getNextEntry()) != null) {
                    filesCount++;
                    try (final var outFile =
Files.newOutputStream(tempPath.resolve(entry.getName()))) {
                        zipInputStream.transferTo(outFile);
                    }
                }
            } finally {
                FileUtils.deleteDirectory(tempPath.toFile());
            }
            FileUtils.deleteDirectory(tempPath.toFile());
            System.out.println("Loop [" + i + "] FILES COUNT: " +
filesCount);
        }

Of course this is a simulated case - but when GC hits, then we are getting
following exception:

java.io.IOException: Stream closed

at
java.base/java.io.PushbackInputStream.ensureOpen(PushbackInputStream.java:77)
at
java.base/java.io.PushbackInputStream.available(PushbackInputStream.java:276)
at
org.apache.commons.io.input.BoundedInputStream.available(BoundedInputStream.java:382)
at
org.apache.commons.io.input.BoundedInputStream.available(BoundedInputStream.java:382)
at
com.github.luben.zstd.ZstdInputStreamNoFinalizer.readInternal(ZstdInputStreamNoFinalizer.java:160)
at
com.github.luben.zstd.ZstdInputStreamNoFinalizer.read(ZstdInputStreamNoFinalizer.java:136)
at com.github.luben.zstd.ZstdInputStream.read(ZstdInputStream.java:103)
at
org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream.read(ZstdCompressorInputStream.java:119)
at
org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:957)
at java.base/java.io.InputStream.transferTo(InputStream.java:795)
at LINE FROM CODE -> zipInputStream.transferTo(outFile);

We are using JAVA 25 and we also tested that this happens also on JAVA 24
and JAVA 26.

Looking forward on getting any insights how to resolve the problem.
______________________________________________

Konrad Endruszkiewicz

Re: Apache Commons Compress - issue with working with ZSTD compression

Posted by Gary Gregory <ga...@gmail.com>.
Hello Konrad,

Please provide a failing unit test, as patch file or a PR on GitHub.
Then, we can try to reproduce the issue.

TY,
Gary

On Tue, May 5, 2026 at 3:24 PM Konrad Endruszkiewicz
<ko...@gmail.com> wrote:
>
> Good day,
>
> I have a following issue. In my project we are working with multiple ZSTD
> archives and we need to decompress them from Java.
>
> The archive.zip is more than 100MB in size.
> Sample code that represents the issue:
>
>         final var filePath = Path.of("archive.zip");
>
>         for (var i = 0; i < 1000; i++) {
>             var filesCount = 0;
>             final var tempPath = Files.createTempDirectory("tmp");
>             try (final var fis = Files.newInputStream(filePath)) {
>                 final var zipInputStream = new ZipArchiveInputStream(fis);
>                 ZipArchiveEntry entry;
>                 while ((entry = zipInputStream.getNextEntry()) != null) {
>                     filesCount++;
>                     try (final var outFile =
> Files.newOutputStream(tempPath.resolve(entry.getName()))) {
>                         zipInputStream.transferTo(outFile);
>                     }
>                 }
>             } finally {
>                 FileUtils.deleteDirectory(tempPath.toFile());
>             }
>             FileUtils.deleteDirectory(tempPath.toFile());
>             System.out.println("Loop [" + i + "] FILES COUNT: " +
> filesCount);
>         }
>
> Of course this is a simulated case - but when GC hits, then we are getting
> following exception:
>
> java.io.IOException: Stream closed
>
> at
> java.base/java.io.PushbackInputStream.ensureOpen(PushbackInputStream.java:77)
> at
> java.base/java.io.PushbackInputStream.available(PushbackInputStream.java:276)
> at
> org.apache.commons.io.input.BoundedInputStream.available(BoundedInputStream.java:382)
> at
> org.apache.commons.io.input.BoundedInputStream.available(BoundedInputStream.java:382)
> at
> com.github.luben.zstd.ZstdInputStreamNoFinalizer.readInternal(ZstdInputStreamNoFinalizer.java:160)
> at
> com.github.luben.zstd.ZstdInputStreamNoFinalizer.read(ZstdInputStreamNoFinalizer.java:136)
> at com.github.luben.zstd.ZstdInputStream.read(ZstdInputStream.java:103)
> at
> org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream.read(ZstdCompressorInputStream.java:119)
> at
> org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:957)
> at java.base/java.io.InputStream.transferTo(InputStream.java:795)
> at LINE FROM CODE -> zipInputStream.transferTo(outFile);
>
> We are using JAVA 25 and we also tested that this happens also on JAVA 24
> and JAVA 26.
>
> Looking forward on getting any insights how to resolve the problem.
> ______________________________________________
>
> Konrad Endruszkiewicz

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org