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/25 08:15:40 UTC
[jackrabbit-filevault] branch master updated: JCRVLT-448 always
close output stream passed to (#126)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
The following commit(s) were added to refs/heads/master by this push:
new e2395b9 JCRVLT-448 always close output stream passed to (#126)
e2395b9 is described below
commit e2395b98f96ff65db9499fb90289f46aa840de70
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Feb 25 09:15:32 2021 +0100
JCRVLT-448 always close output stream passed to (#126)
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;