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 25e9cb306 Add GzipParameters.getModificationInstant()
25e9cb306 is described below
commit 25e9cb3066ca82b1b12ef08e28bc69125254d0aa
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Nov 6 08:25:00 2024 -0500
Add GzipParameters.getModificationInstant()
Add GzipParameters.setModificationInstant(Instant)
---
src/changes/changes.xml | 4 +++-
.../compress/compressors/gzip/GzipParameters.java | 21 +++++++++++++++++++++
.../commons/compress/compressors/GZipTest.java | 7 ++++++-
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 406a69c8b..6f55dcb4b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,11 +44,13 @@ The <action> type attribute can be add,update,fix,remove.
<title>Apache Commons Compress Release Notes</title>
</properties>
<body>
- <release version="1.27.2" date="YYYY-MM-DD" description="This is a feature
and maintenance release. Java 8 or later is required.">
+ <release version="1.28.0" date="YYYY-MM-DD" description="This is a feature
and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="fix" issue="COMPRESS-686" dev="ggregory" due-to="Richard
Blank, Gary Gregory">Better exception messages in
SeekableInMemoryByteChannel.</action>
<action type="fix" dev="ggregory" due-to="yujincheng08, Gary
Gregory">ZipArchiveOutputStream.addRawArchiveEntry() should check
is2PhaseSource #571.</action>
<!-- ADD -->
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add
GzipParameters.getModificationInstant().</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add
GzipParameters.setModificationInstant(Instant).</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary
Gregory">Bump org.apache.commons:commons-parent from 72 to 78 #563, #567, #574,
#582, #587, #595.</action>
<action type="update" dev="ggregory" due-to="Dependabot, Gary
Gregory">Bump com.github.luben:zstd-jni from 1.5.6-4 to 1.5.6-7 #565, #578,
#601.</action>
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 c5c417d5d..c7a98e558 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
@@ -20,6 +20,7 @@
package org.apache.commons.compress.compressors.gzip;
import java.io.OutputStream;
+import java.time.Instant;
import java.util.zip.Deflater;
/**
@@ -102,6 +103,16 @@ public class GzipParameters {
}
+ /**
+ * Gets the most recent modification time (MTIME) of the original file
being compressed.
+ *
+ * @return the most recent modification time.
+ * @since 1.28.0
+ */
+ public Instant getModificationInstant() {
+ return Instant.ofEpochSecond(modificationTime);
+ }
+
/**
* Gets the most recent modification time (MTIME) of the original file
being compressed.
* <p>
@@ -184,6 +195,16 @@ public class GzipParameters {
this.fileName = fileName;
}
+ /**
+ * Sets the modification time (MTIME) of the compressed file.
+ *
+ * @param modificationTime the modification time, in milliseconds
+ * @since 1.28.0
+ */
+ public void setModificationInstant(final Instant modificationTime) {
+ this.modificationTime = modificationTime != null ?
modificationTime.getEpochSecond() : 0;
+ }
+
/**
* Sets the modification time (MTIME) of the compressed file.
* <p>
diff --git
a/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
b/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
index fc4cca128..550dbcc30 100644
--- a/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
@@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
+import java.time.Instant;
import java.util.zip.Deflater;
import java.util.zip.GZIPInputStream;
@@ -43,6 +44,8 @@ import org.junit.jupiter.params.provider.ValueSource;
public final class GZipTest extends AbstractTest {
+ private static final Instant MTIME = Instant.ofEpochSecond(123456000);
+
@Test
public void testConcatenatedStreamsReadFirstOnly() throws Exception {
final File input = getFile("multiple.gz");
@@ -198,7 +201,9 @@ public final class GZipTest extends AbstractTest {
final GzipParameters parameters = new GzipParameters();
parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
- parameters.setModificationTime(123456000);
+ parameters.setModificationInstant(MTIME);
+ assertEquals(MTIME.getEpochSecond(), parameters.getModificationTime());
+ assertEquals(MTIME, parameters.getModificationInstant());
parameters.setOperatingSystem(13);
parameters.setFilename("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());