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 a0e96aa4da27b70ddfc83140b5b3456812310f5b
Author: Gary D. Gregory <[email protected]>
AuthorDate: Sun Dec 22 15:37:37 2024 -0500

    Refactor duplicate constant declarations
---
 .../gzip/GzipCompressorInputStream.java            | 18 ++++----------
 .../gzip/GzipCompressorOutputStream.java           | 20 ++++------------
 .../compress/compressors/gzip/GzipUtils.java       | 28 +++++++++++++++-------
 3 files changed, 28 insertions(+), 38 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 f95727c74..cd7ee4b98 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
@@ -66,14 +66,6 @@ import org.apache.commons.io.input.BoundedInputStream;
  */
 public class GzipCompressorInputStream extends CompressorInputStream 
implements InputStreamStatistics {
 
-    // Header flags
-    // private static final int FTEXT = 0x01; // Uninteresting for us
-    private static final int FHCRC = 0x02;
-    private static final int FEXTRA = 0x04;
-    private static final int FNAME = 0x08;
-    private static final int FCOMMENT = 0x10;
-    private static final int FRESERVED = 0xE0;
-
     /**
      * Checks if the signature matches what is expected for a .gz file.
      *
@@ -223,7 +215,7 @@ public class GzipCompressorInputStream extends 
CompressorInputStream implements
         }
 
         final int flg = inData.readUnsignedByte();
-        if ((flg & FRESERVED) != 0) {
+        if ((flg & GzipUtils.FRESERVED) != 0) {
             throw new IOException("Reserved flags are set in the .gz header");
         }
 
@@ -242,7 +234,7 @@ public class GzipCompressorInputStream extends 
CompressorInputStream implements
         parameters.setOperatingSystem(inData.readUnsignedByte());
 
         // Extra field
-        if ((flg & FEXTRA) != 0) {
+        if ((flg & GzipUtils.FEXTRA) != 0) {
             int xlen = inData.readUnsignedByte();
             xlen |= inData.readUnsignedByte() << 8;
             final byte[] extra = new byte[xlen];
@@ -251,12 +243,12 @@ public class GzipCompressorInputStream extends 
CompressorInputStream implements
         }
 
         // Original file name
-        if ((flg & FNAME) != 0) {
+        if ((flg & GzipUtils.FNAME) != 0) {
             parameters.setFileName(new String(readToNull(inData), 
GzipUtils.GZIP_ENCODING));
         }
 
         // Comment
-        if ((flg & FCOMMENT) != 0) {
+        if ((flg & GzipUtils.FCOMMENT) != 0) {
             parameters.setComment(new String(readToNull(inData), 
GzipUtils.GZIP_ENCODING));
         }
 
@@ -265,7 +257,7 @@ public class GzipCompressorInputStream extends 
CompressorInputStream implements
         // sets this, so it's not worth trying to verify it. GNU gzip 1.4
         // doesn't support this field, but zlib seems to be able to at least
         // skip over it.
-        if ((flg & FHCRC) != 0) {
+        if ((flg & GzipUtils.FHCRC) != 0) {
             parameters.setHeaderCRC(true);
             inData.readShort();
         }
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 2a15f8993..81c84ba42 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
@@ -38,18 +38,6 @@ import 
org.apache.commons.compress.compressors.CompressorOutputStream;
  */
 public class GzipCompressorOutputStream extends 
CompressorOutputStream<OutputStream> {
 
-    /** Header flag indicating an EXTRA subfields collection follows the 
header */
-    private static final int FEXTRA = 1 << 2;
-
-    /** Header flag indicating a file name follows the header */
-    private static final int FNAME = 1 << 3;
-
-    /** Header flag indicating a comment follows the header */
-    private static final int FCOMMENT = 1 << 4;
-
-    /** Header flag indicating a header CRC follows the header */
-    private static final int FHCRC = 1 << 1;
-
     /** Deflater used to compress the data */
     private final Deflater deflater;
 
@@ -180,10 +168,10 @@ public class GzipCompressorOutputStream extends 
CompressorOutputStream<OutputStr
         buffer.order(ByteOrder.LITTLE_ENDIAN);
         buffer.putShort((short) GZIPInputStream.GZIP_MAGIC);
         buffer.put((byte) Deflater.DEFLATED); // compression method (8: 
deflate)
-        buffer.put((byte) ((extra != null ? FEXTRA : 0)
-                | (fileName != null ? FNAME : 0)
-                | (comment != null ? FCOMMENT : 0)
-                | (parameters.getHeaderCRC() ? FHCRC : 0)
+        buffer.put((byte) ((extra != null ? GzipUtils.FEXTRA : 0)
+                | (fileName != null ? GzipUtils.FNAME : 0)
+                | (comment != null ? GzipUtils.FCOMMENT : 0)
+                | (parameters.getHeaderCRC() ? GzipUtils.FHCRC : 0)
         )); // flags
         buffer.putInt((int) 
parameters.getModificationInstant().getEpochSecond());
         // extra flags
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 2aeae2a3f..faddae4a2 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
@@ -33,8 +33,27 @@ import org.apache.commons.compress.compressors.FileNameUtil;
  */
 public class GzipUtils {
 
+    /** Header flag indicating a comment follows the header. */
+    static final int FCOMMENT = 0x10;
+
+    /** Header flag indicating an EXTRA subfields collection follows the 
header. */
+    static final int FEXTRA = 0x04;
+
+    /** Header flag indicating a header CRC follows the header. */
+    static final int FHCRC = 0x02;
+
+    /** Header flag indicating a file name follows the header. */
+    static final int FNAME = 0x08;
+
+    static final int FRESERVED = 0xE0;
+
     private static final FileNameUtil fileNameUtil;
 
+    /**
+     * Charset 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;
+
     static {
         // using LinkedHashMap so .tgz is preferred over .taz as
         // compressed extension of .tar as FileNameUtil will use the
@@ -54,11 +73,6 @@ public class GzipUtils {
         fileNameUtil = new FileNameUtil(uncompressSuffix, ".gz");
     }
 
-    /**
-     * Charset 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 compressed
      * versions are automatically detected and correctly mapped. For example 
the name "package.tar" is mapped to "package.tgz". If no custom mapping is
@@ -85,7 +99,6 @@ public class GzipUtils {
     public static String getCompressedFileName(final String fileName) {
         return fileNameUtil.getCompressedFileName(fileName);
     }
-
     /**
      * Maps the given name of a gzip-compressed file to the name that the file 
should have after uncompression. Commonly used file type specific suffixes like
      * ".tgz" or ".svgz" are automatically detected and correctly mapped. For 
example the name "package.tgz" is mapped to "package.tar". And any file names 
with
@@ -100,7 +113,6 @@ public class GzipUtils {
     public static String getUncompressedFilename(final String fileName) {
         return fileNameUtil.getUncompressedFileName(fileName);
     }
-
     /**
      * Maps the given name of a gzip-compressed file to the name that the file 
should have after uncompression. Commonly used file type specific suffixes like
      * ".tgz" or ".svgz" are automatically detected and correctly mapped. For 
example the name "package.tgz" is mapped to "package.tar". And any file names 
with
@@ -114,7 +126,6 @@ public class GzipUtils {
     public static String getUncompressedFileName(final String fileName) {
         return fileNameUtil.getUncompressedFileName(fileName);
     }
-
     /**
      * Detects common gzip suffixes in the given file name.
      *
@@ -126,7 +137,6 @@ public class GzipUtils {
     public static boolean isCompressedFilename(final String fileName) {
         return fileNameUtil.isCompressedFileName(fileName);
     }
-
     /**
      * Detects common gzip suffixes in the given file name.
      *

Reply via email to