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 992955707 Add ZipArchiveInputStream.createZstdInputStream(InputStream) 
to provide a different InputStream implementation for Zstandard (Zstd) #649
992955707 is described below

commit 992955707756c9da010637879cf814762897b919
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Mar 20 20:12:24 2025 -0400

    Add ZipArchiveInputStream.createZstdInputStream(InputStream) to provide
    a different InputStream implementation for Zstandard (Zstd) #649
---
 src/changes/changes.xml                            |  1 +
 .../archivers/zip/ZipArchiveInputStream.java       | 24 ++++-----
 .../zstandard/ZstdCompressorInputStream.java       |  2 +-
 .../archivers/zip/ZipArchiveInputStreamTest.java   | 62 +++++++++++-----------
 4 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1ef938995..9552e0d44 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -90,6 +90,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
MemoryLimitException.MemoryLimitException(long, int, Throwable) and deprecate 
MemoryLimitException.MemoryLimitException(long, int, Exception).</action>
       <action type="add" issue="COMPRESS-692" dev="ggregory" due-to="Mehmet 
Karaman, Andrey Loskutov, Gary Gregory">Add support for zstd compression in zip 
archives.</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add support for 
XZ compression in ZIP archives.</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory" 
issue="COMPRESS-695">Add 
ZipArchiveInputStream.createZstdInputStream(InputStream) to provide a different 
InputStream implementation for Zstandard (Zstd) #649.</action>
       <!-- UPDATE -->
       <action type="update" dev="sebb">Bump Commons Parent from 79 to 
81</action>
       <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.apache.commons:commons-parent from 72 to 79 #563, #567, #574, 
#582, #587, #595.</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index 7e6acfe83..db89d78c3 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -510,6 +510,18 @@ private void closeEntry() throws IOException {
         lastStoredEntry = null;
     }
 
+    /**
+     * Creates the appropriate InputStream for the Zstd compression method.
+     *
+     * @param in the input stream which should be used for compression.
+     * @return the {@link InputStream} for handling the Zstd compression.
+     * @throws IOException if an I/O error occurs.
+     * @since 1.28.0
+     */
+    protected InputStream createZstdInputStream(final InputStream in) throws 
IOException {
+        return new ZstdCompressorInputStream(in);
+    }
+
     /**
      * If the compressed size of the current entry is included in the entry 
header and there are any outstanding bytes in the underlying stream, then this
      * returns true.
@@ -790,18 +802,6 @@ public ZipArchiveEntry getNextZipEntry() throws 
IOException {
         return current.entry;
     }
 
-    /**
-     * Creates the appropriate InputStream for the ZSTD compression method.
-     *
-     * @param in the input stream which should be used for compression.
-     * @return the {@link InputStream} for handling the Zstd compression.
-     * @throws IOException if an I/O error occurs.
-     * @since 1.28.0
-     */
-    protected InputStream createZstdInputStream(final InputStream in) throws 
IOException {
-        return new ZstdCompressorInputStream(in);
-    }
-
     /**
      * Gets the uncompressed count.
      *
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java
index 30f4fad88..1ca1e716d 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java
@@ -50,7 +50,7 @@ public ZstdCompressorInputStream(final InputStream in) throws 
IOException {
      * @param in         the input stream of compressed data
      * @param bufferPool a configuration of zstd-jni that allows users to 
customize how buffers are recycled. Either a {@link 
com.github.luben.zstd.NoPool} or a
      *                   {@link com.github.luben.zstd.RecyclingBufferPool} is 
allowed here.
-     * @throws IOException if an IO error occurs.
+     * @throws IOException if an I/O error occurs.
      */
     public ZstdCompressorInputStream(final InputStream in, final BufferPool 
bufferPool) throws IOException {
         this.decIS = new ZstdInputStream(countingStream = 
BoundedInputStream.builder().setInputStream(in).get(), bufferPool);
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index f289fba26..c4a24a066 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -62,19 +62,19 @@
 
 public class ZipArchiveInputStreamTest extends AbstractTest {
 
-    private final class ZipArchiveInputStreamAltZstd extends 
ZipArchiveInputStream {
+    private static final class AirliftZipArchiveInputStream extends 
ZipArchiveInputStream {
 
-        boolean used;
+        private boolean used;
 
-        private ZipArchiveInputStreamAltZstd(InputStream inputStream) {
+        private AirliftZipArchiveInputStream(final InputStream inputStream) {
             super(inputStream);
         }
 
         @Override
-        protected InputStream createZstdInputStream(InputStream bis) throws 
IOException {
+        protected InputStream createZstdInputStream(final InputStream bis) 
throws IOException {
             return new ZstdInputStream(bis) {
                 @Override
-                public int read(byte[] outputBuffer, int outputOffset, int 
outputLength) throws IOException {
+                public int read(final byte[] outputBuffer, final int 
outputOffset, final int outputLength) throws IOException {
                     used = true;
                     return super.read(outputBuffer, outputOffset, 
outputLength);
                 }
@@ -343,32 +343,6 @@ public void testProperlyReadsStoredEntries() throws 
IOException {
         }
     }
 
-    @Test
-    public void testAlternativeZstdImplementation() throws IOException {
-        try (InputStream fs = newInputStream("COMPRESS-692/compress-692.zip");
-                ZipArchiveInputStreamAltZstd archive = new 
ZipArchiveInputStreamAltZstd(fs)) {
-            assertFalse(archive.isUsed());
-            ZipArchiveEntry e = archive.getNextEntry();
-            assertNotNull(e);
-            assertEquals(ZipMethod.ZSTD.getCode(), e.getMethod());
-            assertEquals("dolor.txt", e.getName());
-            assertEquals(635, e.getCompressedSize());
-            assertEquals(6066, e.getSize());
-            byte[] data = IOUtils.toByteArray(archive);
-            assertEquals(6066, data.length);
-            assertTrue(archive.isUsed());
-            e = archive.getNextEntry();
-            assertNotNull(e);
-            assertEquals(ZipMethod.ZSTD.getCode(), e.getMethod());
-            assertEquals("ipsum.txt", e.getName());
-            assertEquals(636, e.getCompressedSize());
-            assertEquals(6072, e.getSize());
-            data = IOUtils.toByteArray(archive);
-            assertEquals(6072, data.length);
-            assertNotNull(archive.getNextEntry());
-        }
-    }
-
     @Test
     public void 
testProperlyReadsStoredEntryWithDataDescriptorWithoutSignature() throws 
IOException {
         try (InputStream fs = newInputStream("bla-stored-dd-nosig.zip");
@@ -799,6 +773,32 @@ public void testWriteZipWithLinks() throws IOException {
         }
     }
 
+    @Test
+    public void testZipArchiveInputStreamSubclassReplacement() throws 
IOException {
+        try (InputStream fs = newInputStream("COMPRESS-692/compress-692.zip");
+                AirliftZipArchiveInputStream archive = new 
AirliftZipArchiveInputStream(fs)) {
+            assertFalse(archive.isUsed());
+            ZipArchiveEntry e = archive.getNextEntry();
+            assertNotNull(e);
+            assertEquals(ZipMethod.ZSTD.getCode(), e.getMethod());
+            assertEquals("dolor.txt", e.getName());
+            assertEquals(635, e.getCompressedSize());
+            assertEquals(6066, e.getSize());
+            byte[] data = IOUtils.toByteArray(archive);
+            assertEquals(6066, data.length);
+            assertTrue(archive.isUsed());
+            e = archive.getNextEntry();
+            assertNotNull(e);
+            assertEquals(ZipMethod.ZSTD.getCode(), e.getMethod());
+            assertEquals("ipsum.txt", e.getName());
+            assertEquals(636, e.getCompressedSize());
+            assertEquals(6072, e.getSize());
+            data = IOUtils.toByteArray(archive);
+            assertEquals(6072, data.length);
+            assertNotNull(archive.getNextEntry());
+        }
+    }
+
     @ParameterizedTest
     @ValueSource(booleans = { true, false })
     public void testZipInputStream(final boolean 
allowStoredEntriesWithDataDescriptor) {

Reply via email to