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

    Add optional FHCRC to GZIP header
    
    - Rename some new methods
    - Sort members
    - Normalize whitespace
---
 .../compressors/gzip/GzipCompressorOutputStream.java |  4 ++--
 .../compress/compressors/gzip/GzipParameters.java    | 20 ++++++++++----------
 .../gzip/GzipCompressorOutputStreamTest.java         | 10 +++++-----
 3 files changed, 17 insertions(+), 17 deletions(-)

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 086547760..2a15f8993 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
@@ -183,7 +183,7 @@ public class GzipCompressorOutputStream extends 
CompressorOutputStream<OutputStr
         buffer.put((byte) ((extra != null ? FEXTRA : 0)
                 | (fileName != null ? FNAME : 0)
                 | (comment != null ? FCOMMENT : 0)
-                | (parameters.hasHeaderCRC() ? FHCRC : 0)
+                | (parameters.getHeaderCRC() ? FHCRC : 0)
         )); // flags
         buffer.putInt((int) 
parameters.getModificationInstant().getEpochSecond());
         // extra flags
@@ -208,7 +208,7 @@ public class GzipCompressorOutputStream extends 
CompressorOutputStream<OutputStr
         }
         writeC(fileName, parameters.getFileNameCharset());
         writeC(comment, parameters.getFileNameCharset());
-        if (parameters.hasHeaderCRC()) {
+        if (parameters.getHeaderCRC()) {
             final int v = (int) crc.getValue() & 0xffff;
             out.write(v & 0xff);
             out.write((v >>> 8) & 0xff);
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 f241745fd..6f7662be8 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
@@ -390,6 +390,16 @@ public class GzipParameters {
     }
 
 
+    /**
+     * Returns if the header CRC is to be added (when writing) or was present 
(when reading).
+     *
+     * @return true is header CRC will be added (on write) or was found (after 
read).
+     * @since 1.28.0
+     */
+    public boolean getHeaderCRC() {
+        return headerCRC;
+    }
+
     /**
      * Gets the most recent modification time (MTIME) of the original file 
being compressed.
      *
@@ -433,16 +443,6 @@ public class GzipParameters {
         return operatingSystem;
     }
 
-    /**
-     * Returns if the header CRC is to be added (when writing) or was present 
(when reading).
-     *
-     * @return true is header CRC will be added (on write) or was found (after 
read).
-     * @since 1.28.0
-     */
-    public boolean hasHeaderCRC() {
-        return headerCRC;
-    }
-
     private String requireNonNulByte(final String text) {
         if (StringUtils.isNotEmpty(text) && 
ArrayUtils.contains(text.getBytes(fileNameCharset), (byte) 0)) {
             throw new IllegalArgumentException("String encoded in Charset '" + 
fileNameCharset + "' contains the nul byte 0 which is not supported in gzip.");
diff --git 
a/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java
index 08b08f4be..f6fb70953 100644
--- 
a/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java
@@ -229,7 +229,7 @@ public class GzipCompressorOutputStreamTest {
      * @throws IOException When the test has issues with the underlying file 
system or unexpected gzip operations.
      */
     @Test
-    public void testHcrc() throws IOException, DecoderException {
+    public void testHeaderCrc() throws IOException, DecoderException {
         final GzipParameters parameters = new GzipParameters();
         parameters.setHeaderCRC(true);
         parameters.setModificationTime(0x66554433); // avoid changing time
@@ -249,10 +249,10 @@ public class GzipCompressorOutputStreamTest {
                 + "1e" // flg(FEXTRA|FNAME|FCOMMENT|FHCRC)
                 + "33445566" // mtime little endian
                 + "00" + "03" // xfl os
-                + "0800" + "4242" + "0400" + "43434343" //xlen sfid sflen 
"CCCC"
+                + "0800" + "4242" + "0400" + "43434343" // xlen sfid sflen 
"CCCC"
                 + "4141414100" // "AAAA" with \0
                 + "5a5a5a5a00" // "ZZZZ" with \0
-                + "d842" //crc32 = 839242d8
+                + "d842" // crc32 = 839242d8
                 + "0300" // empty deflate stream
                 + "00000000" // crs32
                 + "00000000" // isize
@@ -265,7 +265,7 @@ public class GzipCompressorOutputStreamTest {
         });
         try (GzipCompressorInputStream gis = new GzipCompressorInputStream(new 
ByteArrayInputStream(result))) {
             final GzipParameters metaData = gis.getMetaData();
-            assertTrue(metaData.hasHeaderCRC());
+            assertTrue(metaData.getHeaderCRC());
             assertEquals(0x66554433, metaData.getModificationTime());
             assertEquals(1, metaData.getExtraField().size());
             final SubField sf = metaData.getExtraField().iterator().next();
@@ -277,7 +277,7 @@ public class GzipCompressorOutputStreamTest {
         }
         // verify that the constructor normally fails on bad HCRC
         assertThrows(ZipException.class, () -> {
-            result[30] = 0x77; //corrupt the low byte of header CRC
+            result[30] = 0x77; // corrupt the low byte of header CRC
             try (GZIPInputStream gis = new GZIPInputStream(new 
ByteArrayInputStream(result))) {
                 // if it does not fail, the hcrc is good.
             }

Reply via email to