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 2022/05/05 17:39:51 UTC
[commons-compress] 03/03: Add SevenZArchiveEntry.setContentMethods(SevenZMethodConfiguration...).
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 1be1abb9523da66d6e537de64215eae14c0b64ea
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu May 5 13:39:43 2022 -0400
Add SevenZArchiveEntry.setContentMethods(SevenZMethodConfiguration...).
---
src/changes/changes.xml | 3 +++
.../archivers/sevenz/SevenZArchiveEntry.java | 19 +++++++++++++++++++
.../archivers/sevenz/SevenZArchiveEntryTest.java | 20 ++++++++++----------
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e2833331..ec2f512a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -122,6 +122,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="COMPRESS-612" type="add" dev="ggregory" due-to="Andre Brait, Gary Gregory">
Improve TAR support for file times #254.
</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">
+ Add SevenZArchiveEntry.setContentMethods(SevenZMethodConfiguration...).
+ </action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">
Bump mockito-core from 3.11.1 to 4.5.1 #209, #224, #231, #235, #243, #253, #286.
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
index 7c2b8142..e3e72064 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
@@ -17,6 +17,7 @@
*/
package org.apache.commons.compress.archivers.sevenz;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
@@ -470,6 +471,24 @@ public class SevenZArchiveEntry implements ArchiveEntry {
}
}
+ /**
+ * Sets the (compression) methods to use for entry's content - the
+ * default is LZMA2.
+ *
+ * <p>Currently only {@link SevenZMethod#COPY}, {@link
+ * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link
+ * SevenZMethod#DEFLATE} are supported when writing archives.</p>
+ *
+ * <p>The methods will be consulted in iteration order to create
+ * the final output.</p>
+ *
+ * @param methods the methods to use for the content
+ * @since 1.22
+ */
+ public void setContentMethods(SevenZMethodConfiguration... methods) {
+ setContentMethods(Arrays.asList(methods));
+ }
+
/**
* Gets the (compression) methods to use for entry's content - the
* default is LZMA2.
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
index fec844b1..6e606768 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
@@ -35,9 +35,9 @@ public class SevenZArchiveEntryTest {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
final SevenZArchiveEntry z3 = new SevenZArchiveEntry();
- z1.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1)));
- z2.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2)));
- z3.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2)));
+ z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1));
+ z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2));
+ z3.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2));
assertNotEquals(z1, z2);
assertNotEquals(z2, z1);
assertEquals(z3, z2);
@@ -48,8 +48,8 @@ public class SevenZArchiveEntryTest {
public void methodOrderMattersInEquals() {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
- z1.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.LZMA2), new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER)));
- z2.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2)));
+ z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2), new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER));
+ z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
assertNotEquals(z1, z2);
assertNotEquals(z2, z1);
}
@@ -58,7 +58,7 @@ public class SevenZArchiveEntryTest {
public void noMethodsIsDifferentFromSomeMethods() {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
- z2.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.COPY)));
+ z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
assertNotEquals(z1, z2);
assertNotEquals(z2, z1);
}
@@ -67,8 +67,8 @@ public class SevenZArchiveEntryTest {
public void oneMethodsIsDifferentFromTwoMethods() {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
- z1.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.COPY)));
- z2.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2)));
+ z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
+ z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
assertNotEquals(z1, z2);
assertNotEquals(z2, z1);
}
@@ -77,8 +77,8 @@ public class SevenZArchiveEntryTest {
public void sameMethodsYieldEqualEntries() {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
- z1.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2)));
- z2.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2)));
+ z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
+ z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
assertEquals(z1, z2);
assertEquals(z2, z1);
}