Skip to content

Commit

Permalink
Add GzipParameters.getModificationInstant()
Browse files Browse the repository at this point in the history
Add GzipParameters.setModificationInstant(Instant)
  • Loading branch information
garydgregory committed Nov 6, 2024
1 parent f8ef32a commit 25e9cb3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.commons.compress.compressors.gzip;

import java.io.OutputStream;
import java.time.Instant;
import java.util.zip.Deflater;

/**
Expand Down Expand Up @@ -102,6 +103,16 @@ public String getFileName() {
}


/**
* 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>
Expand Down Expand Up @@ -184,6 +195,16 @@ public void setFileName(final String fileName) {
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;

Expand All @@ -43,6 +44,8 @@

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");
Expand Down Expand Up @@ -198,7 +201,9 @@ public void testMetadataRoundTrip() throws Exception {

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());
Expand Down

0 comments on commit 25e9cb3

Please sign in to comment.