jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1864770 [1/2] - in /jackrabbit/commons/filevault/trunk: vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/ vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ vault-cli/src/main/java/org/apache/jackrabbit/vault/util/con...
Date Fri, 09 Aug 2019 06:47:18 GMT
Author: kwin
Date: Fri Aug  9 06:47:17 2019
New Revision: 1864770

URL: http://svn.apache.org/viewvc?rev=1864770&view=rev
Log:
JCRVLT-349 clarify and consolidate closing behaviour for input/output
stream being passed to methods

The only remaining method which still closes a passed stream (given as
method argument) is PackageManager.assemble(...) and
PackageManager.rewrap(...).
Use try with resources.

Modified:
    jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/CmdImportCli.java
    jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java
    jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/PropertyValueArtifact.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/SerializerArtifact.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileCopy.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileInputStream.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/Artifact.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractConfig.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractVaultFsConfig.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultMetaInf.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/SimpleCredentialsConfig.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AbstractArtifact.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateManagerImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/VaultFileOutputImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CNDSerializer.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CompressionUtil.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeTypeArtifactHandler.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrArchive.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrExporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Serializer.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipArchive.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipStreamArchive.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackageManager.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/VaultPackage.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/InstallHookProcessorImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/InputStreamPump.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/MD5.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/SHA1.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/BaseMarkupSerializer.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/XMLSerializer.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSpecialDoubleProperties.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/registry/impl/FSRegisteredPackageTest.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/MD5Test.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/SHA1Test.java

Modified: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/CmdImportCli.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/CmdImportCli.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/CmdImportCli.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/CmdImportCli.java Fri Aug  9 06:47:17 2019
@@ -84,13 +84,10 @@ public class CmdImportCli extends Abstra
                 return;
             }
             // todo: move to another location
-            InputStream ins = FileUtils.openInputStream(localFile);
-            try {
+            try (InputStream ins = FileUtils.openInputStream(localFile)) {
                 Session session = vCtx.getFileSystem(addr).getAggregateManager().getSession();
                 session.getWorkspace().importXML(jcrPath, ins, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
                 return;
-            } finally {
-                IOUtils.closeQuietly(ins);
             }
         }
 

Modified: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java Fri Aug  9 06:47:17 2019
@@ -331,9 +331,9 @@ public abstract class AbstractApplicatio
             return;
         }
         Properties props = new Properties();
-        FileInputStream in = new FileInputStream(file);
-        props.load(in);
-        in.close();
+        try (FileInputStream in = new FileInputStream(file)) {
+            props.load(in);
+        }
         Iterator iter = globalEnv.keySet().iterator();
         while (iter.hasNext()) {
             String key = (String) iter.next();

Modified: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java Fri Aug  9 06:47:17 2019
@@ -46,11 +46,9 @@ public class PomProperties {
     public Properties getProperties() {
         if (props == null) {
             props = new Properties();
-            try {
-                InputStream in = PomProperties.class.getClassLoader().getResourceAsStream(pomPropsPath);
+            try (InputStream in = PomProperties.class.getClassLoader().getResourceAsStream(pomPropsPath)) {
                 if (in != null) {
                     props.load(in);
-                    in.close();
                 }
             } catch (IOException e) {
                 // ignore

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/PropertyValueArtifact.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/PropertyValueArtifact.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/PropertyValueArtifact.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/PropertyValueArtifact.java Fri Aug  9 06:47:17 2019
@@ -166,11 +166,10 @@ public class PropertyValueArtifact exten
             tmpFile = File.createTempFile("jcrfs", "dat");
             tmpFile.setLastModified(getLastModified());
             tmpFile.deleteOnExit();
-            FileOutputStream out = new FileOutputStream(tmpFile);
-            InputStream in = getValue().getStream();
-            IOUtils.copy(in, out);
-            in.close();
-            out.close();
+            try (FileOutputStream out = new FileOutputStream(tmpFile);
+                 InputStream in = getValue().getStream()) {
+                IOUtils.copy(in, out);
+            }
         }
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/SerializerArtifact.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/SerializerArtifact.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/SerializerArtifact.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/SerializerArtifact.java Fri Aug  9 06:47:17 2019
@@ -97,13 +97,13 @@ public class SerializerArtifact extends
      * {@inheritDoc}
      */
     public InputStream getInputStream() throws IOException, RepositoryException {
-        DeferredFileOutputStream out = new DeferredFileOutputStream(8192, "vlttmp", ".tmp", null);
-        spool(out);
-        out.close();
-        if (out.isInMemory()) {
-            return new ByteArrayInputStream(out.getData());
-        } else {
-            return new TempFileInputStream(out.getFile());
+        try (DeferredFileOutputStream out = new DeferredFileOutputStream(8192, "vlttmp", ".tmp", null)) {
+            spool(out);
+            if (out.isInMemory()) {
+                return new ByteArrayInputStream(out.getData());
+            } else {
+                return new TempFileInputStream(out.getFile());
+            }
         }
     }
 
@@ -111,17 +111,18 @@ public class SerializerArtifact extends
      * {@inheritDoc}
      */
     public VaultInputSource getInputSource() throws IOException, RepositoryException {
-        DeferredFileOutputStream out = new DeferredFileOutputStream(8192, "vlttmp", ".tmp", null);
-        spool(out);
-        out.close();
         final InputStream in;
         final long size;
-        if (out.isInMemory()) {
-            in = new ByteArrayInputStream(out.getData());
-            size = out.getData().length;
-        } else {
-            in = new TempFileInputStream(out.getFile());
-            size = out.getFile().length();
+        try (DeferredFileOutputStream out = new DeferredFileOutputStream(8192, "vlttmp", ".tmp", null)) {
+            spool(out);
+        
+            if (out.isInMemory()) {
+                in = new ByteArrayInputStream(out.getData());
+                size = out.getData().length;
+            } else {
+                in = new TempFileInputStream(out.getFile());
+                size = out.getFile().length();
+            }
         }
         return new VaultInputSource() {
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileCopy.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileCopy.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileCopy.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileCopy.java Fri Aug  9 06:47:17 2019
@@ -97,24 +97,23 @@ public class VaultFileCopy {
         if (lineFeed != null) {
             base = new LineOutputStream(base, lineFeed);
         }
-        BinaryCheckOutputStream out = new BinaryCheckOutputStream(base);
-        switch (a.getPreferredAccess()) {
-            case SPOOL:
-                a.spool(out);
-                out.close();
-                break;
-            case STREAM:
-                InputStream in = a.getInputStream();
-                byte[] buffer = new byte[8192];
-                int read;
-                while ((read = in.read(buffer)) >= 0) {
-                    out.write(buffer, 0, read);
-                }
-                in.close();
-                out.close();
-                break;
+        try (BinaryCheckOutputStream out = new BinaryCheckOutputStream(base)) {
+            switch (a.getPreferredAccess()) {
+                case SPOOL:
+                    a.spool(out);
+                    break;
+                case STREAM:
+                    try (InputStream in = a.getInputStream()) {
+                        byte[] buffer = new byte[8192];
+                        int read;
+                        while ((read = in.read(buffer)) >= 0) {
+                            out.write(buffer, 0, read);
+                        }
+                    }
+                    break;
+            }
+            binary = out.isBinary();
         }
-        binary = out.isBinary();
         length = localFile.length();
         // try to set last modified
         long lastMod = remoteFile.lastModified();

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileInputStream.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileInputStream.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/VaultFileInputStream.java Fri Aug  9 06:47:17 2019
@@ -67,9 +67,9 @@ public class VaultFileInputStream extend
                 base = a.getInputStream();
             } else {
                 tmpFile = File.createTempFile("vltfs", ".spool");
-                FileOutputStream out = new FileOutputStream(tmpFile);
-                a.spool(out);
-                out.close();
+                try (FileOutputStream out = new FileOutputStream(tmpFile)) {
+                    a.spool(out);
+                }
                 base = new FileInputStream(tmpFile);
             }
         } catch (RepositoryException e) {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/Artifact.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/Artifact.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/Artifact.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/Artifact.java Fri Aug  9 06:47:17 2019
@@ -117,7 +117,7 @@ public interface Artifact extends Dumpab
     /**
      * Writes the content to the given output stream and closes it afterwards.
      * This is the preferred method to use for output-artifacts.
-     *
+     * <p>The specified stream remains open after this method returns.
      * @param out the output stream to spool to
      * @throws IOException if an I/O error occurs
      * @throws RepositoryException if a repository error occurs

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java Fri Aug  9 06:47:17 2019
@@ -100,6 +100,8 @@ public interface WorkspaceFilter extends
 
     /**
      * Returns the source xml that constructs this filter
+     * It is the obligation of the caller to close the returned input stream.
+     * 
      * @return the source xml
      */
     @Nonnull

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractConfig.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractConfig.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractConfig.java Fri Aug  9 06:47:17 2019
@@ -27,7 +27,6 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.vault.util.RejectingEntityResolver;
 import org.apache.jackrabbit.vault.util.xml.serialize.OutputFormat;
 import org.apache.jackrabbit.vault.util.xml.serialize.XMLSerializer;
@@ -84,9 +83,21 @@ abstract public class AbstractConfig {
     abstract protected void doLoad(Element child) throws ConfigurationException;
 
     public boolean load(File configFile) throws IOException, ConfigurationException {
-        return configFile.canRead() && load(FileUtils.openInputStream(configFile));
+        if (configFile.canRead()) {
+            try (InputStream input = FileUtils.openInputStream(configFile)) {
+                return true;
+            }
+        }
+        return false;
     }
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param in
+     * @return
+     * @throws IOException
+     * @throws ConfigurationException
+     */
     public boolean load(InputStream in) throws IOException, ConfigurationException {
         try {
             DocumentBuilderFactory factory =
@@ -102,13 +113,13 @@ abstract public class AbstractConfig {
             throw new ConfigurationException(e);
         } catch (SAXException e) {
             throw new ConfigurationException(e);
-        } finally {
-            IOUtils.closeQuietly(in);
         }
     }
 
     public void save(File configFile) throws IOException {
-        save(FileUtils.openOutputStream(configFile));
+        try (OutputStream output = FileUtils.openOutputStream(configFile)) {
+            save(output);
+        }
     }
     
     public void save(OutputStream out) throws IOException {
@@ -120,8 +131,6 @@ abstract public class AbstractConfig {
             write(ser);
         } catch (SAXException e) {
             throw new IOException(e.toString());
-        } finally {
-            IOUtils.closeQuietly(out);
         }
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractVaultFsConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractVaultFsConfig.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractVaultFsConfig.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/AbstractVaultFsConfig.java Fri Aug  9 06:47:17 2019
@@ -70,38 +70,43 @@ public abstract class AbstractVaultFsCon
 
     public static VaultFsConfig load(File file)
             throws ConfigurationException, IOException {
-        return load(new FileInputStream(file), file.getName());
+        try (InputStream input = new FileInputStream(file)) {
+            return load(input, file.getName());
+        }
     }
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param in
+     * @param name
+     * @return
+     * @throws ConfigurationException
+     * @throws IOException
+     */
     public static VaultFsConfig load(InputStream in, String name)
             throws ConfigurationException, IOException {
-        try {
-            byte[] source = IOUtils.toByteArray(in);
-            Document document = parse(new ByteArrayInputStream(source));
+        byte[] source = IOUtils.toByteArray(in);
+        Document document = parse(new ByteArrayInputStream(source));
 
-            Element doc = document.getDocumentElement();
-            if (!doc.getNodeName().equals("vaultfs")) {
-                throw new ConfigurationException("<vaultfs> expected.");
-            }
-            String v = doc.getAttribute(ATTR_VERSION);
-            if (v == null || v.equals("")) {
-                v = "1.0";
-            }
-            double version = Double.parseDouble(v);
-            AbstractVaultFsConfig config;
-            if (version != VaultFsConfig11.SUPPORTED_VERSION) {
-                throw new ConfigurationException("version " + version + " not supported.");
-            } else {
-                config = new VaultFsConfig11();
-            }
-            config.setSource(source);
-            config.setName(name);
-            config.process(doc);
-            return config;
-        } finally {
-            IOUtils.closeQuietly(in);
+        Element doc = document.getDocumentElement();
+        if (!doc.getNodeName().equals("vaultfs")) {
+            throw new ConfigurationException("<vaultfs> expected.");
         }
-
+        String v = doc.getAttribute(ATTR_VERSION);
+        if (v == null || v.equals("")) {
+            v = "1.0";
+        }
+        double version = Double.parseDouble(v);
+        AbstractVaultFsConfig config;
+        if (version != VaultFsConfig11.SUPPORTED_VERSION) {
+            throw new ConfigurationException("version " + version + " not supported.");
+        } else {
+            config = new VaultFsConfig11();
+        }
+        config.setSource(source);
+        config.setName(name);
+        config.process(doc);
+        return config;
     }
 
     protected Map<String, String> getProperties() {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultMetaInf.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultMetaInf.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultMetaInf.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultMetaInf.java Fri Aug  9 06:47:17 2019
@@ -22,6 +22,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.Reader;
 import java.util.Collection;
 import java.util.Collections;
@@ -35,6 +36,7 @@ import javax.jcr.NamespaceException;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.CloseShieldInputStream;
 import org.apache.jackrabbit.spi.commons.privilege.ParseException;
 import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionReader;
 import org.apache.jackrabbit.vault.fs.api.VaultFsConfig;
@@ -93,6 +95,8 @@ public class DefaultMetaInf implements M
 
     /**
      * Loads a setting based on the name of the system id.
+     * <p>The specified stream remains open after this method returns.
+     * 
      * @param systemId the system id of the setting to load
      * @param in the input stream
      * @return {@code true} if the setting was loaded.
@@ -143,6 +147,15 @@ public class DefaultMetaInf implements M
         return false;
     }
 
+    /**
+     * 
+     * <p>The specified stream remains open after this method returns.
+     * 
+     * @param in
+     * @param systemId
+     * @throws ConfigurationException
+     * @throws IOException
+     */
     public void loadFilter(@Nonnull InputStream in, @Nonnull String systemId)
             throws ConfigurationException, IOException {
         DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
@@ -151,6 +164,13 @@ public class DefaultMetaInf implements M
         log.trace("Loaded filter from {}.", systemId);
     }
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param in
+     * @param systemId
+     * @throws ConfigurationException
+     * @throws IOException
+     */
     public void loadConfig(@Nonnull InputStream in, @Nonnull String systemId)
             throws ConfigurationException, IOException {
         VaultFsConfig config = AbstractVaultFsConfig.load(in, systemId);
@@ -166,14 +186,27 @@ public class DefaultMetaInf implements M
         log.trace("Loaded settings from {}.", systemId);
     }
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param in
+     * @param systemId
+     * @throws IOException
+     */
     public void loadProperties(@Nonnull InputStream in, @Nonnull String systemId)
             throws IOException {
         Properties props = new Properties();
-        props.loadFromXML(in);
+        // prevent the input stream from being closed for achieving a consistens behaviour
+        props.loadFromXML(new CloseShieldInputStream(in));
         setProperties(props);
         log.trace("Loaded properties from {}.", systemId);
     }
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param in
+     * @param systemId
+     * @throws IOException
+     */
     public void loadPrivileges(@Nonnull InputStream in, @Nonnull String systemId)
             throws IOException {
         try {
@@ -311,10 +344,9 @@ public class DefaultMetaInf implements M
             throws IOException {
         if (config != null) {
             File file = new File(metaDir, Constants.CONFIG_XML);
-            IOUtils.copy(
-                    config.getSource(),
-                    FileUtils.openOutputStream(file)
-            );
+            try (OutputStream output = FileUtils.openOutputStream(file)) {
+                IOUtils.copy(config.getSource(), output);
+            }
         }
     }
 
@@ -339,39 +371,37 @@ public class DefaultMetaInf implements M
             throws IOException {
         if (filter != null) {
             File file = new File(metaDir, Constants.FILTER_XML);
-            IOUtils.copy(
-                    filter.getSource(),
-                    FileUtils.openOutputStream(file)
-            );
+            try (OutputStream output = FileUtils.openOutputStream(file)) {
+                IOUtils.copy(filter.getSource(), output);
+            }
         }
     }
 
     protected void loadProperties(@Nonnull File metaDir) throws IOException {
         File file = new File(metaDir, Constants.PROPERTIES_XML);
         if (file.isFile()) {
-            Properties properties = new Properties();
-            properties.loadFromXML(FileUtils.openInputStream(file));
-            this.properties = properties;
+            try (InputStream input = FileUtils.openInputStream(file)) {
+                Properties properties = new Properties();
+                properties.loadFromXML(input);
+                this.properties = properties;
+            }
         }
     }
 
     protected void saveProperties(@Nonnull File metaDir) throws IOException {
         if (properties != null) {
             File file = new File(metaDir, Constants.PROPERTIES_XML);
-            properties.storeToXML(
-                    FileUtils.openOutputStream(file),
-                    "Custom Vault Properties", "utf-8");
+            try (OutputStream output = FileUtils.openOutputStream(file)) {
+                properties.storeToXML(output, "Custom Vault Properties", "utf-8");
+            }
         }
     }
 
     protected void loadPrivileges(@Nonnull File metaDir) throws IOException {
         File file = new File(metaDir, Constants.PRIVILEGES_XML);
         if (file.isFile()) {
-            InputStream in = FileUtils.openInputStream(file);
-            try {
+            try (InputStream in = FileUtils.openInputStream(file)) {
                 loadPrivileges(in, file.getPath());
-            } finally {
-                IOUtils.closeQuietly(in);
             }
         }
     }
@@ -383,17 +413,13 @@ public class DefaultMetaInf implements M
         }
         for (File file: files) {
             if (file.getName().endsWith(".cnd")) {
-                Reader r = null;
-                try {
-                    r = new InputStreamReader(new FileInputStream(file), "utf8");
+                try(Reader r = new InputStreamReader(new FileInputStream(file), "utf8")) {
                     CNDReader reader = ServiceProviderFactory.getProvider().getCNDReader();
                     reader.read(r, file.getName(), null);
                     cnds.add(reader);
                 } catch (IOException e) {
                     log.error("Error while reading CND: {}", e.toString());
                     throw new IOException("Error while reading CND.", e);
-                } finally {
-                    IOUtils.closeQuietly(r);
                 }
             }
         }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java Fri Aug  9 06:47:17 2019
@@ -294,7 +294,9 @@ public class DefaultWorkspaceFilter impl
      * @throws IOException if an I/O error occurs
      */
     public void load(File file) throws IOException, ConfigurationException {
-        load(new FileInputStream(file));
+        try (InputStream input = new FileInputStream(file)) {
+            load(input);
+        }
     }
 
     /**
@@ -322,22 +324,22 @@ public class DefaultWorkspaceFilter impl
     }
 
     /**
-     * Loads the workspace filter from the given input source
+     * Loads the workspace filter from the given input source.
+     * <p>The specified stream remains open after this method returns.
      * @param in source
      * @throws ConfigurationException if the source is not valid
      * @throws IOException if an I/O error occurs
      */
-    public void load(InputStream in) throws IOException, ConfigurationException {
-        try {
-            source = IOUtils.toByteArray(in);
-            in = getSource();
+    public void load(final InputStream in) throws IOException, ConfigurationException {
+        source = IOUtils.toByteArray(in);
+        try (InputStream inCopy = getSource()) {
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             factory.setNamespaceAware(true);
             //factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
             DocumentBuilder builder = factory.newDocumentBuilder();
             // disable DTD loading (bug #36897)
             builder.setEntityResolver(new RejectingEntityResolver());
-            Document document = builder.parse(in);
+            Document document = builder.parse(inCopy);
             Element doc = document.getDocumentElement();
             if (!"workspaceFilter".equals(doc.getNodeName())) {
                 throw new ConfigurationException("<workspaceFilter> expected.");
@@ -360,8 +362,6 @@ public class DefaultWorkspaceFilter impl
         } catch (SAXException e) {
             throw new ConfigurationException(
                     "Configuration file syntax error.", e);
-        } finally {
-            IOUtils.closeQuietly(in);
         }
 
     }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/SimpleCredentialsConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/SimpleCredentialsConfig.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/SimpleCredentialsConfig.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/SimpleCredentialsConfig.java Fri Aug  9 06:47:17 2019
@@ -148,11 +148,12 @@ public class SimpleCredentialsConfig ext
             }
             SecretKeySpec key = new SecretKeySpec(data, 0, KEY_LENGTH, "DES");
             Cipher cipher = Cipher.getInstance("DES");
-            ByteArrayOutputStream out = new ByteArrayOutputStream(data.length);
-            cipher.init(Cipher.DECRYPT_MODE, key);
-            out.write(cipher.update(data, KEY_LENGTH, data.length - KEY_LENGTH));
-            out.write(cipher.doFinal());
-            return out.toString("utf-8");
+            try (ByteArrayOutputStream out = new ByteArrayOutputStream(data.length)) {
+                cipher.init(Cipher.DECRYPT_MODE, key);
+                out.write(cipher.update(data, KEY_LENGTH, data.length - KEY_LENGTH));
+                out.write(cipher.doFinal());
+                return out.toString("utf-8");
+            }
         } catch (Exception e) {
             log.warn("Unable to decrypt data: " + e);
             return null;

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AbstractArtifact.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AbstractArtifact.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AbstractArtifact.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AbstractArtifact.java Fri Aug  9 06:47:17 2019
@@ -139,14 +139,13 @@ public abstract class AbstractArtifact i
      */
     public void spool(OutputStream out)
             throws IOException, RepositoryException {
-        InputStream in = getInputStream();
-        byte[] buffer = new byte[8192];
-        int read;
-        while ((read = in.read(buffer)) >= 0) {
-            out.write(buffer, 0, read);
+        try (InputStream in = getInputStream()) {
+            byte[] buffer = new byte[8192];
+            int read;
+            while ((read = in.read(buffer)) >= 0) {
+                out.write(buffer, 0, read);
+            }
         }
-        in.close();
-        out.close();
     }
 
     /**

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateManagerImpl.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateManagerImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateManagerImpl.java Fri Aug  9 06:47:17 2019
@@ -212,9 +212,8 @@ public class AggregateManagerImpl implem
      * @return the default config
      */
     public static VaultFsConfig getDefaultConfig() {
-        try {
-            InputStream in = AggregateManagerImpl.class.getClassLoader()
-                    .getResourceAsStream(DEFAULT_CONFIG);
+        try (InputStream in = AggregateManagerImpl.class.getClassLoader()
+                    .getResourceAsStream(DEFAULT_CONFIG)) {
             if (in == null) {
                 throw new InternalError("Default config not in classpath: " + DEFAULT_CONFIG);
             }
@@ -231,9 +230,8 @@ public class AggregateManagerImpl implem
      * @return the default config
      */
     public static VaultFsConfig getDefaultBinaryReferencesConfig() {
-        try {
-            InputStream in = AggregateManagerImpl.class.getClassLoader()
-                    .getResourceAsStream(DEFAULT_BINARY_REFERENCES_CONFIG);
+        try (InputStream in = AggregateManagerImpl.class.getClassLoader()
+                    .getResourceAsStream(DEFAULT_BINARY_REFERENCES_CONFIG)) {
             if (in == null) {
                 throw new InternalError("Default config not in classpath: " + DEFAULT_BINARY_REFERENCES_CONFIG);
             }
@@ -250,9 +248,8 @@ public class AggregateManagerImpl implem
      * @return the default workspace filter
      */
     public static DefaultWorkspaceFilter getDefaultWorkspaceFilter() {
-        try {
-            InputStream in = AggregateManagerImpl.class.getClassLoader()
-                    .getResourceAsStream(DEFAULT_WSP_FILTER);
+        try (InputStream in = AggregateManagerImpl.class.getClassLoader()
+                    .getResourceAsStream(DEFAULT_WSP_FILTER)) {
             if (in == null) {
                 throw new InternalError("Default filter not in classpath: " + DEFAULT_WSP_FILTER);
             }
@@ -437,17 +434,15 @@ public class AggregateManagerImpl implem
         } catch (RepositoryException e) {
             // ignore
         }
-        InputStream in = getClass().getClassLoader()
-                .getResourceAsStream(DEFAULT_NODETYPES);
-        try {
+        
+        try (InputStream in = getClass().getClassLoader()
+                .getResourceAsStream(DEFAULT_NODETYPES)) {
             NodeTypeInstaller installer = ServiceProviderFactory.getProvider().getDefaultNodeTypeInstaller(session);
             CNDReader types = ServiceProviderFactory.getProvider().getCNDReader();
             types.read(new InputStreamReader(in, "utf8"), DEFAULT_NODETYPES, null);
             installer.install(null, types);
         } catch (Exception e) {
             throw new RepositoryException("Error while importing nodetypes.", e);
-        } finally {
-            IOUtils.closeQuietly(in);
         }
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/VaultFileOutputImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/VaultFileOutputImpl.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/VaultFileOutputImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/VaultFileOutputImpl.java Fri Aug  9 06:47:17 2019
@@ -30,7 +30,7 @@ import org.apache.jackrabbit.vault.util.
 
 /**
  * Provides methods for writing jcr files. This can either be done by providing
- * an input source or by fetching an output stream. this output stream can be
+ * an input source or by fetching an output stream. This output stream can be
  * acquired via a {@link TransactionImpl}.
  *
  */
@@ -53,6 +53,10 @@ public class VaultFileOutputImpl impleme
         this.is = input;
     }
 
+    /**
+     * This method can only be called once.
+     * @return the returned output stream is implicitly closed via {@link #close()} and doesn't need to be closed.
+     */
     public OutputStream getOutputStream() throws IOException {
         if (out != null) {
             throw new IOException("Output stream already obtained.");

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CNDSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CNDSerializer.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CNDSerializer.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CNDSerializer.java Fri Aug  9 06:47:17 2019
@@ -27,6 +27,7 @@ import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 
+import org.apache.commons.io.output.CloseShieldOutputStream;
 import org.apache.jackrabbit.vault.fs.api.Aggregate;
 import org.apache.jackrabbit.vault.fs.api.SerializationType;
 import org.apache.jackrabbit.vault.fs.io.Serializer;
@@ -60,18 +61,18 @@ public class CNDSerializer implements Se
      * {@inheritDoc}
      */
     public void writeContent(OutputStream out) throws IOException, RepositoryException {
-        Writer w = new OutputStreamWriter(out, "utf-8");
-        for (String prefix: aggregate.getNamespacePrefixes()) {
-            w.write("<'");
-            w.write(prefix);
-            w.write("'='");
-            w.write(escape(aggregate.getNamespaceURI(prefix)));
-            w.write("'>\n");
+        try (Writer w = new OutputStreamWriter(new CloseShieldOutputStream(out), "utf-8")) {
+            for (String prefix: aggregate.getNamespacePrefixes()) {
+                w.write("<'");
+                w.write(prefix);
+                w.write("'='");
+                w.write(escape(aggregate.getNamespaceURI(prefix)));
+                w.write("'>\n");
+            }
+            w.write("\n");
+            
+            writeNodeTypeDef(w, aggregate.getNode());
         }
-        w.write("\n");
-        
-        writeNodeTypeDef(w, aggregate.getNode());
-        w.close();
         out.flush();
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CompressionUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CompressionUtil.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CompressionUtil.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/CompressionUtil.java Fri Aug  9 06:47:17 2019
@@ -155,15 +155,11 @@ public final class CompressionUtil {
     }
 
     static int seemsCompressible(@Nonnull Artifact artifact) {
-        InputStream stream = null;
-        try {
-            stream = artifact.getInputStream();
+        try (InputStream stream = artifact.getInputStream()) {
             byte[] sample = IOUtils.toByteArray(stream, SAMPLE_LENGTH);
             return isCompressible(sample, SAMPLE_LENGTH) ? 1 : -1;
         } catch (RepositoryException | IOException e) {
             log.warn(e.getMessage(), e);
-        } finally {
-            IOUtils.closeQuietly(stream);
         }
         return 0;
     }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java Fri Aug  9 06:47:17 2019
@@ -18,6 +18,7 @@
 package org.apache.jackrabbit.vault.fs.impl.io;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
@@ -446,22 +447,23 @@ public class DocViewSAXImporter extends
         boolean modified = false;
         // Set the jcr:data property
         ValueFactory factory = node.getSession().getValueFactory();
-        Value value = factory.createValue(a.getInputStream());
-        if (node.hasProperty(JcrConstants.JCR_DATA)) {
-            Property data = node.getProperty(JcrConstants.JCR_DATA);
-            if (!value.equals(data.getValue())) {
-                data.setValue(value);
-                // mark jcr:data as modified.
-                importInfo.onModified(data.getPath());
+        try (InputStream input = a.getInputStream()) {
+            Value value = factory.createValue(input);
+            if (node.hasProperty(JcrConstants.JCR_DATA)) {
+                Property data = node.getProperty(JcrConstants.JCR_DATA);
+                if (!value.equals(data.getValue())) {
+                    data.setValue(value);
+                    // mark jcr:data as modified.
+                    importInfo.onModified(data.getPath());
+                    modified = true;
+                }
+            } else {
+                Property data = node.setProperty(JcrConstants.JCR_DATA, value);
+                // mark jcr:data as created
+                importInfo.onCreated(data.getPath());
                 modified = true;
             }
-        } else {
-            Property data = node.setProperty(JcrConstants.JCR_DATA, value);
-            // mark jcr:data as created
-            importInfo.onCreated(data.getPath());
-            modified = true;
         }
-
         // always update last modified if binary was modified (bug #22969)
         if (!node.hasProperty(JcrConstants.JCR_LASTMODIFIED) || modified) {
             Calendar lastModified = Calendar.getInstance();
@@ -1271,7 +1273,9 @@ public class DocViewSAXImporter extends
             Value[] values = new Value[artifacts.size()];
             for (int i = 0; i < values.length; i++) {
                 Artifact a = artifacts.get(i);
-                values[i] = session.getValueFactory().createValue(a.getInputStream());
+                try (InputStream input = a.getInputStream()) {
+                    values[i] = session.getValueFactory().createValue(input);
+                }
             }
             return values;
         }
@@ -1279,7 +1283,9 @@ public class DocViewSAXImporter extends
         public Value getValue(Session session)
                 throws RepositoryException, IOException {
             Artifact a = artifacts.get(0);
-            return session.getValueFactory().createValue(a.getInputStream());
+            try (InputStream input = a.getInputStream()) {
+                return session.getValueFactory().createValue(input);
+            }
         }
 
         public void detach() {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeTypeArtifactHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeTypeArtifactHandler.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeTypeArtifactHandler.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeTypeArtifactHandler.java Fri Aug  9 06:47:17 2019
@@ -65,12 +65,9 @@ public class NodeTypeArtifactHandler ext
         }
         // do import
         CNDImporter importer = new CNDImporter();
-        InputStream in = primary.getInputStream();
-        try {
+        try (InputStream in = primary.getInputStream()) {
             Reader r = new InputStreamReader(in, "utf-8");
             return importer.doImport(parent, primary.getRelativePath(), r, primary.getRelativePath());
-        } finally {
-            in.close();
         }
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java Fri Aug  9 06:47:17 2019
@@ -66,7 +66,7 @@ import static org.apache.jackrabbit.vaul
  * Generic context for exporters
  *
  */
-public abstract class AbstractExporter {
+public abstract class AbstractExporter implements AutoCloseable {
 
     /**
      * default logger
@@ -418,6 +418,12 @@ public abstract class AbstractExporter {
     public abstract void createDirectory(VaultFile file, String relPath)
             throws RepositoryException, IOException;
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param in
+     * @param relPath
+     * @throws IOException
+     */
     public abstract void writeFile(InputStream in, String relPath)
             throws IOException;
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java Fri Aug  9 06:47:17 2019
@@ -709,8 +709,7 @@ public class Importer {
                 } else if (".cnd".equals(ext)) {
                     if (opts.getCndPattern().matcher(repoPath).matches()) {
                         InputStream in = is.getByteStream();
-                        try {
-                            Reader r = new InputStreamReader(in, "utf8");
+                        try (Reader r = new InputStreamReader(in, "utf8")) {
                             CNDReader reader = ServiceProviderFactory.getProvider().getCNDReader();
                             // provide session namespaces
                             reader.read(r, is.getSystemId(), new NamespaceMapping(resolver));
@@ -718,8 +717,6 @@ public class Importer {
                             log.debug("Loaded nodetypes from {}.", repoPath);
                         } catch (IOException e1) {
                             log.error("Error while reading CND.", e1);
-                        } finally {
-                            IOUtils.closeQuietly(in);
                         }
                     }
                     ext = "";
@@ -1083,17 +1080,11 @@ public class Importer {
                 log.debug("Dry run: Would copy patch {} to {}", name, target.getPath());
             } else {
                 log.debug("Copying patch {} to {}", name, target.getPath());
-                InputStream in = null;
-                OutputStream out = null;
-                try {
-                    in = archive.getInputSource(e).getByteStream();
-                    out = FileUtils.openOutputStream(target);
+                try (InputStream in = archive.getInputSource(e).getByteStream();
+                     OutputStream out = FileUtils.openOutputStream(target)) {
                     IOUtils.copy(in, out);
                 } catch (IOException e1) {
                     log.error("Error while copying patch.", e);
-                } finally {
-                    IOUtils.closeQuietly(in);
-                    IOUtils.closeQuietly(out);
                 }
             }
             track("P", name);

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JarExporter.java Fri Aug  9 06:47:17 2019
@@ -181,15 +181,13 @@ public class JarExporter extends Abstrac
                 throw new RepositoryException("Artifact has no content.");
 
             case SPOOL:
-                OutputStream nout = new CloseShieldOutputStream(jOut);
-                a.spool(nout);
+                a.spool(jOut);
                 break;
 
             case STREAM:
-                nout = new CloseShieldOutputStream(jOut);
-                InputStream in = a.getInputStream();
-                IOUtils.copy(in, nout);
-                in.close();
+                try (InputStream in = a.getInputStream()) {
+                    IOUtils.copy(in, jOut);
+                }
                 break;
         }
         jOut.closeEntry();
@@ -203,9 +201,7 @@ public class JarExporter extends Abstrac
         ZipEntry e = new ZipEntry(relPath);
         exportInfo.update(ExportInfo.Type.ADD, e.getName());
         jOut.putNextEntry(e);
-        OutputStream nout = new CloseShieldOutputStream(jOut);
-        IOUtils.copy(in, nout);
-        in.close();
+        IOUtils.copy(in, jOut);
         jOut.closeEntry();
     }
 
@@ -222,9 +218,9 @@ public class JarExporter extends Abstrac
         jOut.putNextEntry(copy);
         if (!entry.isDirectory()) {
             // copy
-            InputStream in = zip.getInputStream(entry);
-            IOUtils.copy(in, jOut);
-            in.close();
+            try (InputStream in = zip.getInputStream(entry)) {
+                IOUtils.copy(in, jOut);
+            }
         }
         jOut.closeEntry();
         if (changeCompressionLevel) {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrArchive.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrArchive.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrArchive.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrArchive.java Fri Aug  9 06:47:17 2019
@@ -129,7 +129,9 @@ public class JcrArchive extends Abstract
         // filter
         for (Entry entry: dir.getChildren()) {
             VaultInputSource src = getInputSource(entry);
-            inf.load(src.getByteStream(), src.getSystemId());
+            try (InputStream input = src.getByteStream()) {
+                inf.load(input, src.getSystemId());
+            }
         }
         if (inf.getFilter() == null) {
             log.debug("Archive {} does not contain filter definition.", this);

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrExporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrExporter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrExporter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/JcrExporter.java Fri Aug  9 06:47:17 2019
@@ -133,11 +133,11 @@ public class JcrExporter extends Abstrac
             case SPOOL:
                 // we can't support spool
             case STREAM:
-                InputStream in = a.getInputStream();
-                Binary b = content.getSession().getValueFactory().createBinary(in);
-                content.setProperty(JcrConstants.JCR_DATA, b);
-                b.dispose();
-                in.close();
+                try (InputStream in = a.getInputStream()) {
+                    Binary b = content.getSession().getValueFactory().createBinary(in);
+                    content.setProperty(JcrConstants.JCR_DATA, b);
+                    b.dispose();
+                }
                 break;
         }
         Calendar now = Calendar.getInstance();

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java Fri Aug  9 06:47:17 2019
@@ -141,17 +141,16 @@ public class PlatformExporter extends Ab
                 throw new RepositoryException("Artifact has no content.");
 
             case SPOOL:
-                FileOutputStream out = new FileOutputStream(local);
-                a.spool(out);
-                out.close();
+                try (FileOutputStream out = new FileOutputStream(local)) {
+                    a.spool(out);
+                }
                 break;
 
             case STREAM:
-                InputStream in = a.getInputStream();
-                out = new FileOutputStream(local);
-                IOUtils.copy(in, out);
-                in.close();
-                out.close();
+                try (InputStream in = a.getInputStream();
+                     OutputStream out = new FileOutputStream(local)) {
+                    IOUtils.copy(in, out);
+                }
                 break;
         }
         if (a.getLastModified() >= 0) {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Serializer.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Serializer.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Serializer.java Fri Aug  9 06:47:17 2019
@@ -30,6 +30,12 @@ import org.apache.jackrabbit.vault.fs.ap
  */
 public interface Serializer {
 
+    /**
+     * <p>The specified stream remains open after this method returns.
+     * @param out
+     * @throws IOException
+     * @throws RepositoryException
+     */
     void writeContent(@Nonnull OutputStream out) throws IOException, RepositoryException;
 
     @Nonnull

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipArchive.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipArchive.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipArchive.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ZipArchive.java Fri Aug  9 06:47:17 2019
@@ -110,8 +110,8 @@ public class ZipArchive extends Abstract
             String path = entry.getName();
             // check for meta inf
             if (path.startsWith(Constants.META_DIR + "/")) {
-                try {
-                    inf.load(jar.getInputStream(entry), file.getPath() + ":" + path);
+                try (InputStream input = jar.getInputStream(entry)) {
+                    inf.load(input, file.getPath() + ":" + path);
                 } catch (ConfigurationException e1) {
                     throw new IOException(e1);
                 }

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=1864770&r1=1864769&r2=1864770&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 Fri Aug  9 06:47:17 2019
@@ -106,7 +106,7 @@ public class ZipStreamArchive extends Ab
     private final byte[] buffer = new byte[0x10000];
 
     /**
-     * Creates an ew zip stream archive on the given input stream.
+     * Creates a new zip stream archive on the given input stream.
      * @param in the input stream to read from.
      */
     public ZipStreamArchive(@Nonnull InputStream in) {
@@ -273,6 +273,9 @@ public class ZipStreamArchive extends Ab
 
     @Override
     public void close() {
+        if (in != null) {
+            IOUtils.closeQuietly(in);
+        }
         if (raf != null) {
             try {
                 raf.close();

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackageManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackageManager.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackageManager.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackageManager.java Fri Aug  9 06:47:17 2019
@@ -108,7 +108,7 @@ public interface PackageManager {
     /**
      * Assembles a package using the given meta information. The package
      * is directly streamed to the given output stream.
-     *
+     * <p>The specified stream is closed after this method returns.
      * @param s the repository session
      * @param opts the export options
      * @param out the output stream to write to
@@ -138,6 +138,7 @@ public interface PackageManager {
     /**
      * Re-wraps the given package with the definition provided in the export
      * options.
+     * <p>The specified stream is closed after this method returns.
      * @param opts export options
      * @param src source package
      * @param out destination output stream

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/VaultPackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/VaultPackage.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/VaultPackage.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/VaultPackage.java Fri Aug  9 06:47:17 2019
@@ -93,12 +93,15 @@ public interface VaultPackage extends Pa
     File getFile();
 
     /**
-     * Closes this package and releases underlying data.
+     * Closes this package and releases underlying data. 
+     * This will also close the underlying {@link Archive} if it has been opened.
      */
     void close();
 
     /**
-     * Returns the underlying package archive
+     * Returns the underlying package archive.
+     * This does not need to be closed explicitly but rather is implicitly closed via
+     * a call to {@link #close()}.
      * @return the archive or {@code null} if already closed
      */
     Archive getArchive();

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/InstallHookProcessorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/InstallHookProcessorImpl.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/InstallHookProcessorImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/InstallHookProcessorImpl.java Fri Aug  9 06:47:17 2019
@@ -108,17 +108,12 @@ public class InstallHookProcessorImpl im
         File jarFile = File.createTempFile("vaulthook", ".jar");
         Hook hook = new Hook(input.getSystemId(), jarFile, classLoader);
 
-        OutputStream out = null;
-        InputStream in = input.getByteStream();
-        try {
-            out = FileUtils.openOutputStream(jarFile);
+        try (OutputStream out = FileUtils.openOutputStream(jarFile);
+             InputStream in = input.getByteStream()) {
             IOUtils.copy(in, out);
         } catch (IOException e) {
             hook.destroy();
             throw e;
-        } finally {
-            IOUtils.closeQuietly(in);
-            IOUtils.closeQuietly(out);
         }
         initHook(hook);
     }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java Fri Aug  9 06:47:17 2019
@@ -215,10 +215,10 @@ public class JcrPackageManagerImpl exten
             for (Archive.Entry e: spfArchive.getSubPackageEntries()) {
                 InputStream in = spfArchive.openInputStream(e);
                 if (in != null) {
-                    Archive subArchive = new ZipStreamArchive(in);
-                    PackageId[] subIds = extract(subArchive, options, replace);
-                    ids.addAll(Arrays.asList(subIds));
-                    subArchive.close();
+                    try (Archive subArchive = new ZipStreamArchive(in)) {
+                        PackageId[] subIds = extract(subArchive, options, replace);
+                        ids.addAll(Arrays.asList(subIds));
+                    }
                 }
             }
         }
@@ -360,18 +360,17 @@ public class JcrPackageManagerImpl exten
 
         // update this content
         Node contentNode = packNode.getNode(JcrConstants.JCR_CONTENT);
-        InputStream in;
-        try {
-            in = FileUtils.openInputStream(pack.getFile());
+        
+        try (InputStream in = FileUtils.openInputStream(pack.getFile())){
+            // stay jcr 1.0 compatible
+            //noinspection deprecation
+            contentNode.setProperty(JcrConstants.JCR_DATA, in);
+            contentNode.setProperty(JcrConstants.JCR_LASTMODIFIED, now);
+            contentNode.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE);
+            packNode.getSession().save();
         } catch (IOException e) {
             throw new PackageException(e);
         }
-        // stay jcr 1.0 compatible
-        //noinspection deprecation
-        contentNode.setProperty(JcrConstants.JCR_DATA, in);
-        contentNode.setProperty(JcrConstants.JCR_LASTMODIFIED, now);
-        contentNode.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE);
-        packNode.getSession().save();
         pack.close();
         dispatch(PackageEvent.Type.ASSEMBLE, id, null);
     }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java Fri Aug  9 06:47:17 2019
@@ -37,13 +37,10 @@ import javax.jcr.Session;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.vault.fs.Mounter;
-import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.api.RepositoryAddress;
 import org.apache.jackrabbit.vault.fs.api.VaultFileSystem;
 import org.apache.jackrabbit.vault.fs.api.VaultFsConfig;
-import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
 import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
-import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
 import org.apache.jackrabbit.vault.fs.config.MetaInf;
 import org.apache.jackrabbit.vault.fs.impl.AggregateManagerImpl;
 import org.apache.jackrabbit.vault.fs.io.JarExporter;
@@ -57,9 +54,6 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.events.impl.PackageEventDispatcher;
 import org.apache.jackrabbit.vault.util.Constants;
 
-import static org.apache.jackrabbit.vault.packaging.registry.impl.JcrPackageRegistry.DEFAULT_PACKAGE_ROOT_PATH;
-import static org.apache.jackrabbit.vault.packaging.registry.impl.JcrPackageRegistry.DEFAULT_PACKAGE_ROOT_PATH_PREFIX;
-
 /**
  * Implements the package manager
  */
@@ -191,57 +185,57 @@ public class PackageManagerImpl implemen
         if (metaInf == null) {
             metaInf = new DefaultMetaInf();
         }
-        JarExporter exporter = new JarExporter(out, opts.getCompressionLevel());
-        exporter.open();
-        exporter.setProperties(metaInf.getProperties());
-        ProgressTracker tracker = null;
-        if (opts.getListener() != null) {
-            tracker = new ProgressTracker();
-            exporter.setVerbose(opts.getListener());
-        }
-
-        // merge
-        MetaInf inf = opts.getMetaInf();
-        ZipFile zip = new ZipFile(src.getFile(), ZipFile.OPEN_READ);
-        if (opts.getPostProcessor() == null) {
-            // no post processor, we keep all files except the properties
-            Enumeration e = zip.entries();
-            while (e.hasMoreElements()) {
-                ZipEntry entry = (ZipEntry) e.nextElement();
-                String path = entry.getName();
-                if (!path.equals(Constants.META_DIR + "/" + Constants.PROPERTIES_XML)) {
-                    exporter.write(zip, entry);
+        try (JarExporter exporter = new JarExporter(out, opts.getCompressionLevel())) {
+            exporter.open();
+            exporter.setProperties(metaInf.getProperties());
+            ProgressTracker tracker = null;
+            if (opts.getListener() != null) {
+                tracker = new ProgressTracker();
+                exporter.setVerbose(opts.getListener());
+            }
+    
+            // merge
+            MetaInf inf = opts.getMetaInf();
+            try (ZipFile zip = new ZipFile(src.getFile(), ZipFile.OPEN_READ)) {
+                if (opts.getPostProcessor() == null) {
+                    // no post processor, we keep all files except the properties
+                    Enumeration<? extends ZipEntry> e = zip.entries();
+                    while (e.hasMoreElements()) {
+                        ZipEntry entry = (ZipEntry) e.nextElement();
+                        String path = entry.getName();
+                        if (!path.equals(Constants.META_DIR + "/" + Constants.PROPERTIES_XML)) {
+                            exporter.write(zip, entry);
+                        }
+                    }
+                } else {
+                    Set<String> keep = new HashSet<String>();
+                    keep.add(Constants.META_DIR + "/");
+                    keep.add(Constants.META_DIR + "/" + Constants.NODETYPES_CND);
+                    keep.add(Constants.META_DIR + "/" + Constants.CONFIG_XML);
+                    keep.add(Constants.META_DIR + "/" + Constants.FILTER_XML);
+                    Enumeration<? extends ZipEntry> e = zip.entries();
+                    while (e.hasMoreElements()) {
+                        ZipEntry entry = (ZipEntry) e.nextElement();
+                        String path = entry.getName();
+                        if (!path.startsWith(Constants.META_DIR + "/") || keep.contains(path)) {
+                            exporter.write(zip, entry);
+                        }
+                    }
                 }
             }
-        } else {
-            Set<String> keep = new HashSet<String>();
-            keep.add(Constants.META_DIR + "/");
-            keep.add(Constants.META_DIR + "/" + Constants.NODETYPES_CND);
-            keep.add(Constants.META_DIR + "/" + Constants.CONFIG_XML);
-            keep.add(Constants.META_DIR + "/" + Constants.FILTER_XML);
-            Enumeration e = zip.entries();
-            while (e.hasMoreElements()) {
-                ZipEntry entry = (ZipEntry) e.nextElement();
-                String path = entry.getName();
-                if (!path.startsWith(Constants.META_DIR + "/") || keep.contains(path)) {
-                    exporter.write(zip, entry);
-                }
+    
+            // write updated properties
+            ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
+            inf.getProperties().storeToXML(tmpOut, "FileVault Package Properties", "utf-8");
+            exporter.writeFile(new ByteArrayInputStream(tmpOut.toByteArray()), Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
+            if (tracker != null) {
+                tracker.track("A", Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
+            }
+    
+            if (opts.getPostProcessor() != null) {
+                opts.getPostProcessor().process(exporter);
             }
         }
-        zip.close();
-
-        // write updated properties
-        ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
-        inf.getProperties().storeToXML(tmpOut, "FileVault Package Properties", "utf-8");
-        exporter.writeFile(new ByteArrayInputStream(tmpOut.toByteArray()), Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
-        if (tracker != null) {
-            tracker.track("A", Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
-        }
-
-        if (opts.getPostProcessor() != null) {
-            opts.getPostProcessor().process(exporter);
-        }
-        exporter.close();
     }
 
     @Nullable

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/InputStreamPump.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/InputStreamPump.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/InputStreamPump.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/InputStreamPump.java Fri Aug  9 06:47:17 2019
@@ -68,6 +68,11 @@ public class InputStreamPump extends Inp
     }
 
     public interface Pump {
+        /**
+         * <p>The specified stream remains open after this method returns.
+         * @param in
+         * @throws Exception
+         */
         void run(InputStream in) throws Exception;
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/MD5.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/MD5.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/MD5.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/MD5.java Fri Aug  9 06:47:17 2019
@@ -76,26 +76,24 @@ public class MD5 {
     }
 
     public static MD5 digest(InputStream in) throws IOException {
+        MessageDigest md;
         try {
-            MessageDigest md;
-            try {
-                md = MessageDigest.getInstance("md5");
-            } catch (NoSuchAlgorithmException e) {
-                throw new IllegalArgumentException(e.toString());
-            }
-            byte[] buffer = new byte[8192];
-            int read;
-            while ((read = in.read(buffer)) > 0) {
-                md.update(buffer, 0, read);
-            }
-            return new MD5(md.digest());
-        } finally {
-            in.close();
+            md = MessageDigest.getInstance("md5");
+        } catch (NoSuchAlgorithmException e) {
+            throw new IllegalArgumentException(e.toString());
         }
+        byte[] buffer = new byte[8192];
+        int read;
+        while ((read = in.read(buffer)) > 0) {
+            md.update(buffer, 0, read);
+        }
+        return new MD5(md.digest());
     }
 
     public static MD5 digest(File file) throws IOException {
-        return digest(new FileInputStream(file));
+        try (InputStream input = new FileInputStream(file)) {
+            return digest(input);
+        }
     }
 
     public String toString() {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/SHA1.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/SHA1.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/SHA1.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/SHA1.java Fri Aug  9 06:47:17 2019
@@ -87,26 +87,24 @@ public class SHA1 {
     }
 
     public static SHA1 digest(InputStream in) throws IOException {
+        MessageDigest md;
         try {
-            MessageDigest md;
-            try {
-                md = MessageDigest.getInstance("SHA-1");
-            } catch (NoSuchAlgorithmException e) {
-                throw new IllegalArgumentException(e.toString());
-            }
-            byte[] buffer = new byte[8192];
-            int read;
-            while ((read = in.read(buffer)) > 0) {
-                md.update(buffer, 0, read);
-            }
-            return new SHA1(md.digest());
-        } finally {
-            in.close();
+            md = MessageDigest.getInstance("SHA-1");
+        } catch (NoSuchAlgorithmException e) {
+            throw new IllegalArgumentException(e.toString());
         }
+        byte[] buffer = new byte[8192];
+        int read;
+        while ((read = in.read(buffer)) > 0) {
+            md.update(buffer, 0, read);
+        }
+        return new SHA1(md.digest());
     }
 
     public static SHA1 digest(File file) throws IOException {
-        return digest(FileUtils.openInputStream(file));
+        try (InputStream input = FileUtils.openInputStream(file)) {
+            return digest(input);
+        }
     }
 
     public String toString() {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/BaseMarkupSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/BaseMarkupSerializer.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/BaseMarkupSerializer.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/BaseMarkupSerializer.java Fri Aug  9 06:47:17 2019
@@ -275,7 +275,9 @@ public abstract class BaseMarkupSerializ
         return this;
     }
 
-
+    /**
+     * <p>The specified stream will not be closed by this class.
+     */
     public void setOutputByteStream(OutputStream output) {
         if (output == null) {
             String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
@@ -288,6 +290,9 @@ public abstract class BaseMarkupSerializ
     }
 
 
+    /**
+     * <p>The specified writer will not be closed by this class.
+     */
     public void setOutputCharStream(Writer writer) {
         if (writer == null) {
             String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/XMLSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/XMLSerializer.java?rev=1864770&r1=1864769&r2=1864770&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/XMLSerializer.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/xml/serialize/XMLSerializer.java Fri Aug  9 06:47:17 2019
@@ -175,8 +175,11 @@ public class XMLSerializer extends BaseM
      * using the specified output format. If <tt>format</tt> is null,
      * will use a default output format.
      *
+     * <p>The specified writer will not be closed by this class.
+     * 
      * @param writer The writer to use
      * @param format The output format to use, null for the default
+     * 
      */
     public XMLSerializer(Writer writer, OutputFormat format) {
         super(format != null ? format : new OutputFormat(Method.XML, null, false));
@@ -189,7 +192,8 @@ public class XMLSerializer extends BaseM
      * Constructs a new serializer that writes to the specified output
      * stream using the specified output format. If <tt>format</tt>
      * is null, will use a default output format.
-     *
+     * <p>The specified stream will not be closed by this class.
+     * 
      * @param output The output stream to use
      * @param format The output format to use, null for the default
      */



Mime
View raw message