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 2023/10/29 13:56:35 UTC

(commons-compress) branch master updated (519d752b -> 75642094)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from 519d752b Add a generic type parameter to ArchiveOutputStream and avoid unchecked/unconfirmed type casts in subclasses
     new b241be6f Inline single use local variable
     new 9bb31aa9 Format tweak
     new 4fb96200 Add SevenZOutputFile.putArchiveEntry(SevenZArchiveEntry) and deprecate putArchiveEntry(ArchiveEntry)
     new 23207033 Use try-with-resources
     new 6c828e91 Use try-with-resources
     new 75642094 Use try-with-resources

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  1 +
 .../compress/archivers/examples/Archiver.java      |  3 +-
 .../archivers/sevenz/SevenZOutputFile.java         | 22 ++++++++++++--
 .../commons/compress/archivers/SevenZTestCase.java |  7 ++---
 .../harmony/pack200/tests/ArchiveTest.java         | 35 +++++++++-------------
 5 files changed, 39 insertions(+), 29 deletions(-)


(commons-compress) 04/06: Use try-with-resources

Posted by gg...@apache.org.
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 232070335ddfc5d0b478cb107e7fb18c5d60e9a9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 29 09:47:53 2023 -0400

    Use try-with-resources
---
 .../java/org/apache/commons/compress/archivers/SevenZTestCase.java | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java b/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java
index 98d6dde5..4e95ec9b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java
@@ -64,9 +64,8 @@ public class SevenZTestCase extends AbstractTestCase {
     }
 
     private void createArchive(final SevenZMethod method) throws Exception {
-        final SevenZOutputFile outArchive = new SevenZOutputFile(output);
-        outArchive.setContentCompression(method);
-        try {
+        try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
+            outArchive.setContentCompression(method);
             SevenZArchiveEntry entry;
 
             entry = outArchive.createArchiveEntry(file1, file1.getName());
@@ -78,8 +77,6 @@ public class SevenZTestCase extends AbstractTestCase {
             outArchive.putArchiveEntry(entry);
             copy(file2, outArchive);
             outArchive.closeArchiveEntry();
-        } finally {
-            outArchive.close();
         }
     }
 


(commons-compress) 06/06: Use try-with-resources

Posted by gg...@apache.org.
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 7564209440091169f62b625f9e9d4bc597c54fb8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 29 09:56:30 2023 -0400

    Use try-with-resources
---
 .../compress/harmony/pack200/tests/ArchiveTest.java        | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
index b48d3285..4e112c3f 100755
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
@@ -118,14 +118,12 @@ public class ArchiveTest {
 
     @Test
     public void testAlternativeConstructor() throws IOException, URISyntaxException, Pack200Exception {
-        final JarInputStream inStream = new JarInputStream(new FileInputStream(
-                new File(Archive.class.getResource(
-                        "/pack200/sqlUnpacked.jar").toURI())));
-        file = File.createTempFile("sql", ".pack.gz");
-        file.deleteOnExit();
-        out = new FileOutputStream(file);
-        new Archive(inStream, out, null).pack();
-        inStream.close();
+        try (JarInputStream inStream = new JarInputStream(new FileInputStream(new File(Archive.class.getResource("/pack200/sqlUnpacked.jar").toURI())))) {
+            file = File.createTempFile("sql", ".pack.gz");
+            file.deleteOnExit();
+            out = new FileOutputStream(file);
+            new Archive(inStream, out, null).pack();
+        }
         out.close();
     }
 


(commons-compress) 03/06: Add SevenZOutputFile.putArchiveEntry(SevenZArchiveEntry) and deprecate putArchiveEntry(ArchiveEntry)

Posted by gg...@apache.org.
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 4fb9620098f81ed68167b298cb1f5f1cd31d0563
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 29 09:44:49 2023 -0400

    Add SevenZOutputFile.putArchiveEntry(SevenZArchiveEntry) and deprecate
    putArchiveEntry(ArchiveEntry)
---
 src/changes/changes.xml                                 |  1 +
 .../commons/compress/archivers/examples/Archiver.java   |  3 ++-
 .../compress/archivers/sevenz/SevenZOutputFile.java     | 17 ++++++++++++++++-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 85550977..0df7e959 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -63,6 +63,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipUtils.getCompressedFileName(String) and deprecate getCompressedFilename(String).</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipUtils.getUncompressedFileName(String) and deprecate getUncompressedFilename(String).</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipUtils.isCompressedFileName(String) and deprecate isCompressedFilename(String).</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add SevenZOutputFile.putArchiveEntry(SevenZArchiveEntry) and deprecate putArchiveEntry(ArchiveEntry).</action>
       <!-- FIX -->
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ArArchiveInputStream.isBSDLongName(String).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ArArchiveInputStream.isGNULongName(String).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
index cd6f137a..5c595d81 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
@@ -39,6 +39,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
 import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.commons.compress.utils.IOUtils;
@@ -168,7 +169,7 @@ public class Archiver {
                 Objects.requireNonNull(attrs);
                 final String name = directory.relativize(path).toString().replace('\\', '/');
                 if (!name.isEmpty()) {
-                    final ArchiveEntry archiveEntry = target.createArchiveEntry(path,
+                    final SevenZArchiveEntry archiveEntry = target.createArchiveEntry(path,
                         isFile || name.endsWith("/") ? name : name + "/");
                     target.putArchiveEntry(archiveEntry);
                     if (isFile) {
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
index 8d6589a5..9dc622f1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
@@ -379,9 +379,24 @@ public class SevenZOutputFile implements Closeable {
      * {@link #closeArchiveEntry()} to complete the process.
      *
      * @param archiveEntry describes the entry
+     * @deprecated Use {@link #putArchiveEntry(SevenZArchiveEntry)}.
      */
+    @Deprecated
     public void putArchiveEntry(final ArchiveEntry archiveEntry) {
-        files.add((SevenZArchiveEntry) archiveEntry);
+        putArchiveEntry((SevenZArchiveEntry) archiveEntry);
+    }
+
+    /**
+     * Records an archive entry to add.
+     *
+     * The caller must then write the content to the archive and call
+     * {@link #closeArchiveEntry()} to complete the process.
+     *
+     * @param archiveEntry describes the entry
+     * @since 1.25.0
+     */
+    public void putArchiveEntry(final SevenZArchiveEntry archiveEntry) {
+        files.add(archiveEntry);
     }
 
     /**


(commons-compress) 02/06: Format tweak

Posted by gg...@apache.org.
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 9bb31aa96d5f7c80897053f06ace2ca06dd0727c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 29 09:39:15 2023 -0400

    Format tweak
---
 .../apache/commons/compress/archivers/sevenz/SevenZOutputFile.java    | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
index 16d4c7be..8d6589a5 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
@@ -57,12 +57,16 @@ import org.apache.commons.compress.utils.TimeUtils;
 
 /**
  * Writes a 7z file.
+ *
  * @since 1.6
  */
 public class SevenZOutputFile implements Closeable {
+
     private class OutputStreamWrapper extends OutputStream {
+
         private static final int BUF_SIZE = 8192;
         private final ByteBuffer buffer = ByteBuffer.allocate(BUF_SIZE);
+
         @Override
         public void close() throws IOException {
             // the file will be closed by the containing class's close method


(commons-compress) 05/06: Use try-with-resources

Posted by gg...@apache.org.
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 6c828e91a6cd852e061cd0c6a86b357dcce6ea83
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 29 09:51:20 2023 -0400

    Use try-with-resources
---
 .../compress/harmony/pack200/tests/ArchiveTest.java | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
index c5e5d3f7..b48d3285 100755
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
@@ -193,8 +193,7 @@ public class ArchiveTest {
 
     @Test
     public void testHelloWorld() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarFile(new File(Archive.class.getResource(
-                "/pack200/hw.jar").toURI()));
+        in = new JarFile(new File(Archive.class.getResource("/pack200/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         file.deleteOnExit();
         out = new FileOutputStream(file);
@@ -203,25 +202,21 @@ public class ArchiveTest {
         out.close();
 
         // now unpack
-        final InputStream in2 = new FileInputStream(file);
         final File file2 = File.createTempFile("helloworld", ".jar");
         file2.deleteOnExit();
-        final JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
-        final org.apache.commons.compress.harmony.unpack200.Archive archive = new org.apache.commons.compress.harmony.unpack200.Archive(
-                in2, out2);
-        archive.unpack();
-        out2.close();
-        in2.close();
+        try (InputStream in2 = new FileInputStream(file);
+                JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2))) {
+            final org.apache.commons.compress.harmony.unpack200.Archive archive = new org.apache.commons.compress.harmony.unpack200.Archive(in2, out2);
+            archive.unpack();
+        }
 
         try (JarFile jarFile = new JarFile(file2)) {
-            final JarEntry entry = jarFile
-                    .getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
+            final JarEntry entry = jarFile.getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
             assertNotNull(entry);
             try (InputStream ours = jarFile.getInputStream(entry)) {
 
                 final JarFile jarFile2 = new JarFile(new File(Segment.class.getResource("/pack200/hw.jar").toURI()));
-                final JarEntry entry2 = jarFile2
-                        .getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
+                final JarEntry entry2 = jarFile2.getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
                 assertNotNull(entry2);
 
                 final InputStream expected = jarFile2.getInputStream(entry2);


(commons-compress) 01/06: Inline single use local variable

Posted by gg...@apache.org.
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 b241be6f81a045c566aac66295f1ba0adc9a09cb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 29 09:38:17 2023 -0400

    Inline single use local variable
---
 .../org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
index 697e74ad..16d4c7be 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
@@ -377,8 +377,7 @@ public class SevenZOutputFile implements Closeable {
      * @param archiveEntry describes the entry
      */
     public void putArchiveEntry(final ArchiveEntry archiveEntry) {
-        final SevenZArchiveEntry entry = (SevenZArchiveEntry) archiveEntry;
-        files.add(entry);
+        files.add((SevenZArchiveEntry) archiveEntry);
     }
 
     /**