commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject commons-compress git commit: COMPRESS-341 listing of 7z archives
Date Sun, 20 Mar 2016 20:12:04 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master f9334473b -> 9ff8334ff


COMPRESS-341 listing of 7z archives


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/9ff8334f
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/9ff8334f
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/9ff8334f

Branch: refs/heads/master
Commit: 9ff8334ff25822f70a8313e14c8499891dc47688
Parents: f933447
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Mar 20 21:11:36 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Mar 20 21:11:36 2016 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                            |  4 ++++
 .../compress/archivers/sevenz/SevenZFile.java      | 17 +++++++++++++++++
 .../compress/archivers/sevenz/SevenZFileTest.java  | 17 +++++++++++++++++
 3 files changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9ff8334f/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 809aa08..d9929f6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,10 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
     <release version="1.11" date="not released, yet"
              description="Release 1.11">
+      <action issue="COMPRESS-341" type="add" date="2016-03-20">
+        New method SevenZFile.getEntries can be used to list the
+        contents of a 7z archive.
+      </action>
       <action issue="COMPRESS-343" type="fix" date="2016-03-17"
               due-to="Rene Preissel">
         Native Memory Leak in Sevenz-DeflateDecoder.

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9ff8334f/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 4a86dd2..3ea9369 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -157,6 +157,23 @@ public class SevenZFile implements Closeable {
         return entry;
     }
     
+    /**
+     * Returns meta-data of all archive entries.
+     *
+     * <p>This method only provides meta-data, the entries can not be
+     * used to read the contents, you still need to process all
+     * entries in order using {@link #getNextEntry} for that.</p>
+     *
+     * <p>The content methods are only available for entries that have
+     * already been reached via {@link #getNextEntry}.</p>
+     *
+     * @return meta-data of all archive entries.
+     * @since 1.11
+     */
+    public Iterable<SevenZArchiveEntry> getEntries() {
+        return Arrays.asList(archive.files);
+    }
+    
     private Archive readHeaders(byte[] password) throws IOException {
         final byte[] signature = new byte[6];
         file.readFully(signature);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9ff8334f/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index a57d4cb..7ed4f11 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Random;
 
@@ -243,6 +244,22 @@ public class SevenZFileTest extends AbstractTestCase {
         }
     }
 
+    @Test
+    public void getEntriesOfUnarchiveTest() throws IOException {
+        SevenZFile sevenZFile = new SevenZFile(getFile("bla.7z"));
+        try {
+            Iterable<SevenZArchiveEntry> entries = sevenZFile.getEntries();
+            Iterator<SevenZArchiveEntry> iter = entries.iterator();
+            SevenZArchiveEntry entry = iter.next();
+            assertEquals("test1.xml", entry.getName());
+            entry = iter.next();
+            assertEquals("test2.xml", entry.getName());
+            assertFalse(iter.hasNext());
+        } finally {
+            sevenZFile.close();
+        }
+    }
+    
     private void test7zUnarchive(File f, SevenZMethod m, byte[] password) throws Exception
{
         SevenZFile sevenZFile = new SevenZFile(f, password);
         try {


Mime
View raw message