You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/03/17 19:17:41 UTC

[commons-compress] branch master updated (a7bfe76e -> 7ed71e86)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from a7bfe76e Javadoc
     new ac8c5e1e Sort member
     new 7ed71e86 [COMPRESS-600] Add capability to configure Deflater strategy in GzipCompressorOutputStream: GzipParameters.setDeflateStrategy(int).

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  1 +
 .../gzip/GzipCompressorOutputStream.java           |  1 +
 .../compress/compressors/gzip/GzipParameters.java  | 26 ++++++++++++++++++
 .../archivers/tar/TarArchiveOutputStreamTest.java  | 32 +++++++++++-----------
 .../gzip/GzipParametersTest.java}                  | 21 ++++++++------
 5 files changed, 57 insertions(+), 24 deletions(-)
 copy src/test/java/org/apache/commons/compress/{archivers/jar/JarMarkerTest.java => compressors/gzip/GzipParametersTest.java} (60%)


[commons-compress] 01/02: Sort member

Posted by gg...@apache.org.
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 ac8c5e1e1f8571e47e98bce97c890f45167a3aa2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Mar 17 14:43:11 2023 -0400

    Sort member
---
 .../archivers/tar/TarArchiveOutputStreamTest.java  | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)

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 ffa98eac..1595b374 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
@@ -754,22 +754,6 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase {
         assertEquals("6 a=b\n", new String(data, 512, 6, UTF_8));
     }
 
-    private byte[] writePaxHeader(final Map<String, String> m) throws Exception {
-        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII")) {
-            tos.writePaxHeaders(new TarArchiveEntry("x"), "foo", m);
-
-            // add a dummy entry so data gets written
-            final TarArchiveEntry t = new TarArchiveEntry("foo");
-            t.setSize(10 * 1024);
-            tos.putArchiveEntry(t);
-            tos.write(new byte[10 * 1024]);
-            tos.closeArchiveEntry();
-        }
-
-        return bos.toByteArray();
-    }
-
     /**
      * @see "https://issues.apache.org/jira/browse/COMPRESS-642"
      */
@@ -791,4 +775,20 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase {
         tos.close();
     }
 
+    private byte[] writePaxHeader(final Map<String, String> m) throws Exception {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII")) {
+            tos.writePaxHeaders(new TarArchiveEntry("x"), "foo", m);
+
+            // add a dummy entry so data gets written
+            final TarArchiveEntry t = new TarArchiveEntry("foo");
+            t.setSize(10 * 1024);
+            tos.putArchiveEntry(t);
+            tos.write(new byte[10 * 1024]);
+            tos.closeArchiveEntry();
+        }
+
+        return bos.toByteArray();
+    }
+
 }


[commons-compress] 02/02: [COMPRESS-600] Add capability to configure Deflater strategy in GzipCompressorOutputStream: GzipParameters.setDeflateStrategy(int).

Posted by gg...@apache.org.
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 7ed71e86c5fb6c38ab14eb53e511244909c6ba4d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Mar 17 15:17:36 2023 -0400

    [COMPRESS-600] Add capability to configure Deflater strategy in
    GzipCompressorOutputStream: GzipParameters.setDeflateStrategy(int).
---
 src/changes/changes.xml                            |  1 +
 .../gzip/GzipCompressorOutputStream.java           |  1 +
 .../compress/compressors/gzip/GzipParameters.java  | 26 ++++++++++++++
 .../compressors/gzip/GzipParametersTest.java       | 40 ++++++++++++++++++++++
 4 files changed, 68 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index aa43075b..66b3d9e0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" issue="COMPRESS-633" dev="ggregory" due-to="Daniel Santos, Bruno P. Kinoshita, Gary Gregory">Add encryption support for SevenZ #332.</action>
       <action type="add" issue="COMPRESS-613" dev="ggregory" due-to="Andre Brait, Gary Gregory, Bruno P. Kinoshita">Support for extra time data in Zip archives #345.</action>      
       <action type="add" issue="COMPRESS-621" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.zip.DefaultBackingStoreSupplier to write to a custom folder instead of the default temporary folder.</action>
+      <action type="add" issue="COMPRESS-600" dev="ggregory" due-to="Gary Gregory, Pascal Davoust">Add capability to configure Deflater strategy in GzipCompressorOutputStream: GzipParameters.setDeflateStrategy(int).</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Dependabot">Bump mockito.version from 4.8.0 to 4.11.0 #328, #331, #340, #348.</action>
       <action type="update" dev="ggregory" due-to="Gary Gregory">Bump pmd from 6.50.0 to 6.53.0.</action>
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 7b1975ae..ee7a74a5 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
@@ -83,6 +83,7 @@ public class GzipCompressorOutputStream extends CompressorOutputStream {
     public GzipCompressorOutputStream(final OutputStream out, final GzipParameters parameters) throws IOException {
         this.out = out;
         this.deflater = new Deflater(parameters.getCompressionLevel(), true);
+        this.deflater.setStrategy(parameters.getDeflateStrategy());
         this.deflateBuffer = new byte[parameters.getBufferSize()];
         writeHeader(parameters);
     }
diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipParameters.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipParameters.java
index 33e22518..7b5927e4 100644
--- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipParameters.java
+++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipParameters.java
@@ -25,6 +25,8 @@ import java.util.zip.Deflater;
 /**
  * Parameters for the GZIP compressor.
  *
+ * @see GzipCompressorInputStream
+ * @see GzipCompressorOutputStream
  * @since 1.7
  */
 public class GzipParameters {
@@ -35,6 +37,7 @@ public class GzipParameters {
     private String comment;
     private int operatingSystem = 255; // Unknown OS by default
     private int bufferSize = 512;
+    private int deflateStrategy = Deflater.DEFAULT_STRATEGY;
 
     /**
      * Gets size of the buffer used to retrieve compressed data.
@@ -54,6 +57,18 @@ public class GzipParameters {
         return compressionLevel;
     }
 
+    /**
+     * Gets the deflater strategy.
+     * 
+     * @return the deflater strategy, {@link Deflater#DEFAULT_STRATEGY} by default.
+     * @see #setDeflateStrategy(int)
+     * @see Deflater#setStrategy(int)
+     * @since 1.23
+     */
+    public int getDeflateStrategy() {
+        return deflateStrategy;
+    }
+
     public String getFilename() {
         return filename;
     }
@@ -100,6 +115,17 @@ public class GzipParameters {
         this.compressionLevel = compressionLevel;
     }
 
+    /**
+     * Sets the deflater strategy.
+     *
+     * @param deflateStrategy the new compression strategy
+     * @see Deflater#setStrategy(int)
+     * @since 1.23
+     */
+    public void setDeflateStrategy(int deflateStrategy) {
+        this.deflateStrategy = deflateStrategy;
+    }
+
     /**
      * Sets the name of the compressed file.
      *
diff --git a/src/test/java/org/apache/commons/compress/compressors/gzip/GzipParametersTest.java b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipParametersTest.java
new file mode 100644
index 00000000..866bc3d8
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipParametersTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.commons.compress.compressors.gzip;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.zip.Deflater;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link GzipParameters}.
+ */
+public class GzipParametersTest {
+
+    @Test
+    public void testDeflaterStrategy() {
+        final GzipParameters gzipParameters = new GzipParameters();
+        assertEquals(Deflater.DEFAULT_STRATEGY, gzipParameters.getDeflateStrategy());
+        gzipParameters.setDeflateStrategy(Deflater.HUFFMAN_ONLY);
+        assertEquals(Deflater.HUFFMAN_ONLY, gzipParameters.getDeflateStrategy());
+    }
+}