You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2021/02/24 14:05:49 UTC

[jackrabbit-filevault] branch bugfix/JCRVLT-448-always-close-outputstream created (now e8335df)

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

kwin pushed a change to branch bugfix/JCRVLT-448-always-close-outputstream
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git.


      at e8335df  JCRVLT-448 always close output stream passed to JcrPackageManager.rewrap(...) and assemble(...)

This branch includes the following new commits:

     new e8335df  JCRVLT-448 always close output stream passed to JcrPackageManager.rewrap(...) and assemble(...)

The 1 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.



[jackrabbit-filevault] 01/01: JCRVLT-448 always close output stream passed to JcrPackageManager.rewrap(...) and assemble(...)

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch bugfix/JCRVLT-448-always-close-outputstream
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit e8335df199098e182aef872f8abb42229d278369
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Feb 24 15:05:36 2021 +0100

    JCRVLT-448 always close output stream passed to
    JcrPackageManager.rewrap(...) and assemble(...)
---
 .../apache/jackrabbit/vault/fs/io/JarExporter.java | 11 ++--
 .../vault/packaging/impl/PackageManagerImpl.java   | 66 +++++++++++-----------
 2 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java
index 07774c9..b898372 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java
@@ -33,7 +33,6 @@ import java.util.zip.ZipFile;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.CloseShieldOutputStream;
 import org.apache.jackrabbit.vault.fs.api.Artifact;
 import org.apache.jackrabbit.vault.fs.api.VaultFile;
 import org.apache.jackrabbit.vault.fs.impl.io.CompressionUtil;
@@ -99,7 +98,7 @@ public class JarExporter extends AbstractExporter {
 
     /**
      * Constructs a new jar exporter that writes to the output stream.
-     *
+     * The given output stream is closed when calling {@link #close()}.
      * @param out the output stream
      */
     public JarExporter(OutputStream out) {
@@ -108,7 +107,8 @@ public class JarExporter extends AbstractExporter {
 
     /**
      * Constructs a new jar exporter that writes to the output stream.
-     *
+     * The given output stream is closed when calling {@link #close()}.
+     * 
      * @param out   the output stream
      * @param level level the compression level
      */
@@ -141,6 +141,10 @@ public class JarExporter extends AbstractExporter {
         if (jOut != null) {
             jOut.close();
             jOut = null;
+        } else {
+            if (out != null) {
+                out.close();
+            }
         }
     }
 
@@ -228,5 +232,4 @@ public class JarExporter extends AbstractExporter {
         }
     }
 
-
 }
\ No newline at end of file
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java
index a9c0c57..71a6758 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java
@@ -131,42 +131,40 @@ public class PackageManagerImpl implements PackageManager {
     @Override
     public void assemble(Session s, ExportOptions opts, OutputStream out)
             throws IOException, RepositoryException {
-        RepositoryAddress addr;
-        try {
-            String mountPath = opts.getMountPath();
-            if (mountPath == null || mountPath.length() == 0) {
-                mountPath = "/";
+        try (JarExporter exporter = new JarExporter(out, opts.getCompressionLevel())) {
+            RepositoryAddress addr;
+            try {
+                String mountPath = opts.getMountPath();
+                if (mountPath == null || mountPath.length() == 0) {
+                    mountPath = "/";
+                }
+                addr = new RepositoryAddress("/" + s.getWorkspace().getName() + mountPath);
+            } catch (URISyntaxException e) {
+                throw new IllegalArgumentException(e);
+            }
+            MetaInf metaInf = opts.getMetaInf();
+            if (metaInf == null) {
+                metaInf = new DefaultMetaInf();
             }
-            addr = new RepositoryAddress("/" + s.getWorkspace().getName() + mountPath);
-        } catch (URISyntaxException e) {
-            throw new IllegalArgumentException(e);
-        }
-        MetaInf metaInf = opts.getMetaInf();
-        if (metaInf == null) {
-            metaInf = new DefaultMetaInf();
-        }
 
-        VaultFsConfig config = metaInf.getConfig();
-        if (metaInf.getProperties() != null) {
-            if ("true".equals(metaInf.getProperties().getProperty(PackageProperties.NAME_USE_BINARY_REFERENCES))) {
-                config = AggregateManagerImpl.getDefaultBinaryReferencesConfig();
+            VaultFsConfig config = metaInf.getConfig();
+            if (metaInf.getProperties() != null) {
+                if ("true".equals(metaInf.getProperties().getProperty(PackageProperties.NAME_USE_BINARY_REFERENCES))) {
+                    config = AggregateManagerImpl.getDefaultBinaryReferencesConfig();
+                }
             }
-        }
 
-        VaultFileSystem jcrfs = Mounter.mount(config, metaInf.getFilter(), addr, opts.getRootPath(), s);
-        JarExporter exporter = new JarExporter(out, opts.getCompressionLevel());
-        exporter.setProperties(metaInf.getProperties());
-        if (opts.getListener() != null) {
-            exporter.setVerbose(opts.getListener());
-        }
-        if (opts.getPostProcessor() != null) {
+            VaultFileSystem jcrfs = Mounter.mount(config, metaInf.getFilter(), addr, opts.getRootPath(), s);
+            exporter.setProperties(metaInf.getProperties());
+            if (opts.getListener() != null) {
+                exporter.setVerbose(opts.getListener());
+            }
             exporter.export(jcrfs.getRoot(), true);
-            opts.getPostProcessor().process(exporter);
-            exporter.close();
-        } else {
-            exporter.export(jcrfs.getRoot());
+            if (opts.getPostProcessor() != null) {
+                opts.getPostProcessor().process(exporter);
+            }
+            jcrfs.unmount();
         }
-        jcrfs.unmount();
     }
 
     /**
@@ -204,11 +202,11 @@ public class PackageManagerImpl implements PackageManager {
     @Override
     public void rewrap(ExportOptions opts, VaultPackage src, OutputStream out)
             throws IOException {
-        MetaInf metaInf = opts.getMetaInf();
-        if (metaInf == null) {
-            metaInf = new DefaultMetaInf();
-        }
         try (JarExporter exporter = new JarExporter(out, opts.getCompressionLevel())) {
+            MetaInf metaInf = opts.getMetaInf();
+            if (metaInf == null) {
+                metaInf = new DefaultMetaInf();
+            }
             exporter.open();
             exporter.setProperties(metaInf.getProperties());
             ProgressTracker tracker = null;