You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gr...@apache.org on 2009/04/19 13:07:44 UTC

svn commit: r766447 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java

Author: grobmeier
Date: Sun Apr 19 11:07:42 2009
New Revision: 766447

URL: http://svn.apache.org/viewvc?rev=766447&view=rev
Log:
added test which reads the entries from a nested archive

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java?rev=766447&r1=766446&r2=766447&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java Sun Apr 19 11:07:42 2009
@@ -110,4 +110,47 @@
         out.close();
         in.close();
     }
+    
+    /**
+     * Checks if all entries from a nested archive can be read.
+     * The archive: OSX_ArchiveWithNestedArchive.zip contains:
+     * NestedArchiv.zip and test.xml3.
+     * 
+     * The nested archive:  NestedArchive.zip contains test1.xml and test2.xml
+     * 
+     * @throws Exception
+     */
+    public void testListAllFilesWithNestedArchive() throws Exception {
+        final File input = getFile("archives/OSX_ArchiveWithNestedArchive.zip");
+       
+        List results = new ArrayList();
+
+        final InputStream is = new FileInputStream(input);
+        ArchiveInputStream in = null;
+        try {
+            in = new ArchiveStreamFactory().createArchiveInputStream("zip", is);
+
+            ZipArchiveEntry entry = null;
+            while((entry = (ZipArchiveEntry)in.getNextEntry()) != null) {
+                results.add((entry.getName()));
+
+                ArchiveInputStream nestedIn = new ArchiveStreamFactory().createArchiveInputStream("zip", in);
+                ZipArchiveEntry nestedEntry = null;
+                while((nestedEntry = (ZipArchiveEntry)nestedIn.getNextEntry()) != null) {
+                    results.add(nestedEntry.getName());
+                }
+               // nested stream must not be closed here
+            }
+        } finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+        is.close();
+        
+        results.contains("NestedArchiv.zip");
+        results.contains("test1.xml");
+        results.contains("test2.xml");
+        results.contains("test3.xml");
+    }
 }