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/01/10 03:36:19 UTC

[commons-compress] 01/02: Refactor and comment

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 faa8b444f6e67afe8552262d7576e55e8c5eb4bc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 9 22:35:31 2023 -0500

    Refactor and comment
---
 .../compress/compressors/gzip/GzipCompressorInputStream.java       | 6 ++----
 .../compress/compressors/gzip/GzipCompressorOutputStream.java      | 6 ++----
 .../org/apache/commons/compress/compressors/gzip/GzipUtils.java    | 7 +++++++
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
index 63ae8e3f..f75e78c8 100644
--- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
@@ -18,8 +18,6 @@
  */
 package org.apache.commons.compress.compressors.gzip;
 
-import static java.nio.charset.StandardCharsets.ISO_8859_1;
-
 import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInput;
@@ -287,12 +285,12 @@ public class GzipCompressorInputStream extends CompressorInputStream
 
         // Original file name
         if ((flg & FNAME) != 0) {
-            parameters.setFilename(new String(readToNull(inData), ISO_8859_1));
+            parameters.setFilename(new String(readToNull(inData), GzipUtils.GZIP_ENCODING));
         }
 
         // Comment
         if ((flg & FCOMMENT) != 0) {
-            parameters.setComment(new String(readToNull(inData), ISO_8859_1));
+            parameters.setComment(new String(readToNull(inData), GzipUtils.GZIP_ENCODING));
         }
 
         // Header "CRC16" which is actually a truncated CRC32 (which isn't
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 8c1a0131..604398bb 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
@@ -18,8 +18,6 @@
  */
 package org.apache.commons.compress.compressors.gzip;
 
-import static java.nio.charset.StandardCharsets.ISO_8859_1;
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
@@ -197,12 +195,12 @@ public class GzipCompressorOutputStream extends CompressorOutputStream {
         out.write(buffer.array());
 
         if (filename != null) {
-            out.write(filename.getBytes(ISO_8859_1));
+            out.write(filename.getBytes(GzipUtils.GZIP_ENCODING));
             out.write(0);
         }
 
         if (comment != null) {
-            out.write(comment.getBytes(ISO_8859_1));
+            out.write(comment.getBytes(GzipUtils.GZIP_ENCODING));
             out.write(0);
         }
     }
diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
index b0cdb649..013adae2 100644
--- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
+++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
@@ -18,6 +18,8 @@
  */
 package org.apache.commons.compress.compressors.gzip;
 
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -51,6 +53,11 @@ public class GzipUtils {
         fileNameUtil = new FileNameUtil(uncompressSuffix, ".gz");
     }
 
+    /**
+     * Encoding for file name and comments per the <a href="https://tools.ietf.org/html/rfc1952">GZIP File Format Specification</a>
+     */
+    static final Charset GZIP_ENCODING = StandardCharsets.ISO_8859_1;
+
     /**
      * Maps the given file name to the name that the file should have after
      * compression with gzip. Common file types with custom suffixes for