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

Reply via email to