jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1866356 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java test/java/org/apache/jackrabbit/vault/fs/io/ZipArchiveTest.java
Date Wed, 04 Sep 2019 07:04:55 GMT
Author: kwin
Date: Wed Sep  4 07:04:55 2019
New Revision: 1866356

URL: http://svn.apache.org/viewvc?rev=1866356&view=rev
Log:
JCRVLT-362 expose input stream also for META-INF entries

This closes #57

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/io/ZipArchiveTest.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java?rev=1866356&r1=1866355&r2=1866356&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java
Wed Sep  4 07:04:55 2019
@@ -135,23 +135,13 @@ public class ZipStreamArchive extends Ab
         inf = new DefaultMetaInf();
 
         // scan the zip and copy data to temporary file
-        ZipInputStream zin = new ZipInputStream(in);
-
-        try {
+        try (ZipInputStream zin = new ZipInputStream(in)) {
             ZipEntry entry;
             while ((entry = zin.getNextEntry()) != null) {
                 String name = entry.getName();
-                // check for meta inf
-                if (name.startsWith(Constants.META_DIR + "/")) {
-                    try {
-                        inf.load(new CloseShieldInputStream(zin), "inputstream:" + name);
-                    } catch (ConfigurationException e) {
-                        throw new IOException(e);
-                    }
-                }
                 String[] names = Text.explode(name, '/');
+                EntryImpl je = root;
                 if (names.length > 0) {
-                    EntryImpl je = root;
                     for (int i=0; i<names.length; i++) {
                         if (i == names.length -1 && !entry.isDirectory()) {
                             // copy stream
@@ -166,6 +156,15 @@ public class ZipStreamArchive extends Ab
                         log.debug("scanning jar: {}", name);
                     }
                 }
+                // extract meta information
+                if (name.startsWith(Constants.META_DIR + "/")) {
+                    try (InputStream input = createInputStream(je)) {
+                        // load from previous entryImpl
+                        inf.load(input, "inputstream:" + name);
+                    } catch (ConfigurationException e) {
+                        throw new IOException(e);
+                    }
+                }
             }
             if (inf.getFilter() == null) {
                 log.debug("Zip stream does not contain filter definition.");
@@ -185,8 +184,6 @@ public class ZipStreamArchive extends Ab
             if (inf.getNodeTypes().isEmpty()) {
                 log.debug("Zip stream does not contain nodetypes.");
             }
-        } finally {
-            IOUtils.closeQuietly(zin);
         }
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/io/ZipArchiveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/io/ZipArchiveTest.java?rev=1866356&r1=1866355&r2=1866356&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/io/ZipArchiveTest.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/io/ZipArchiveTest.java
Wed Sep  4 07:04:55 2019
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -32,21 +33,27 @@ public class ZipArchiveTest {
 
     @Test
     public void testSmallArchiveViaStream() throws IOException {
-        InputStream in = getClass().getResourceAsStream("/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip");
-        ZipStreamArchive a = new ZipStreamArchive(in);
-        a.open(true);
-        Properties props = a.getMetaInf().getProperties();
-        assertEquals("Package Name", "atomic-counter-test", props.getProperty("name"));
-        a.close();
+        try (InputStream in = getClass().getResourceAsStream("/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip");
+             ZipStreamArchive a = new ZipStreamArchive(in)) {
+            a.open(true);
+            Properties props = a.getMetaInf().getProperties();
+            assertEquals("Package Name", "atomic-counter-test", props.getProperty("name"));
+            Archive.Entry entry = a.getEntry("META-INF/vault/properties.xml");
+            try (InputStream i = a.openInputStream(entry)) {
+                DefaultMetaInf metaInf = new DefaultMetaInf();
+                metaInf.loadProperties(i, "inputstream");
+                assertEquals("Package Name", "atomic-counter-test", metaInf.getProperties().getProperty("name"));
+            }
+        }
     }
 
     @Test
     public void testSmallArchiveViaFile() throws IOException {
         File file = new File(getClass().getResource("/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip").getFile());
-        ZipArchive a = new ZipArchive(file, false);
-        a.open(true);
-        Properties props = a.getMetaInf().getProperties();
-        assertEquals("Package Name", "atomic-counter-test", props.getProperty("name"));
-        a.close();
+        try (ZipArchive a = new ZipArchive(file, false)) {
+            a.open(true);
+            Properties props = a.getMetaInf().getProperties();
+            assertEquals("Package Name", "atomic-counter-test", props.getProperty("name"));
+        }
     }
 }
\ No newline at end of file



Mime
View raw message