Repository: tomee
Updated Branches:
  refs/heads/master a13eebd65 -> a3402b526


TOMEE-1935 Fixes #44 several resource closing, thanks Svetlin Zarev for the 
patch


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a3402b52
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a3402b52
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a3402b52

Branch: refs/heads/master
Commit: a3402b52657b33c597b3eb9cb6f035e5bf35a6c0
Parents: a13eebd
Author: Romain manni-Bucau <rmannibu...@gmail.com>
Authored: Tue Sep 20 16:08:14 2016 +0200
Committer: Romain manni-Bucau <rmannibu...@gmail.com>
Committed: Tue Sep 20 16:08:14 2016 +0200

----------------------------------------------------------------------
 .../classic/ReloadableEntityManagerFactory.java |  4 +--
 .../openejb/config/sys/SaxAppCtxConfig.java     | 23 ++++++------
 .../openejb/core/managed/RAFPassivater.java     | 11 +++---
 .../openejb/core/managed/SimplePassivater.java  | 26 ++++++++------
 .../openejb/core/stateful/RAFPassivater.java    | 12 +++----
 .../openejb/core/stateful/SimplePassivater.java | 12 +++----
 .../core/webservices/ProviderWrapper.java       |  6 ++--
 .../apache/openejb/service/ScanJarService.java  | 18 +++++-----
 .../org/apache/openejb/util/JarCreator.java     | 37 +++++++++++---------
 .../org/apache/openejb/util/UpdateChecker.java  | 17 +++++----
 .../openejb/jpa/integration/MakeTxLookup.java   |  6 ++--
 11 files changed, 88 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
index 8b4bb59..c61b207 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
@@ -616,13 +616,11 @@ public class ReloadableEntityManagerFactory implements 
EntityManagerFactory, Ser
             persistence.setVersion(info.getPersistenceXMLSchemaVersion());
             persistence.getPersistenceUnit().add(pu);
 
-            try {
-                final FileWriter writer = new FileWriter(file);
+            try (final FileWriter writer = new FileWriter(file)) {
                 final JAXBContext jc = 
JAXBContextFactory.newInstance(Persistence.class);
                 final Marshaller marshaller = jc.createMarshaller();
                 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, 
Boolean.TRUE);
                 marshaller.marshal(persistence, writer);
-                writer.close();
             } catch (final Exception e) {
                 LOGGER.error("can't dump pu " + 
reloadableEntityManagerFactory.getPUname() + " in file " + file, e);
             }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
index 98629c2..b0b9ecf 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
@@ -129,23 +129,26 @@ public class SaxAppCtxConfig {
             private void importFile(final String path) throws SAXException {
                 final File file = new File(path);
                 if (file.exists()) {
-                    try {
-                        parse(module, new InputSource(new 
FileInputStream(file)), envEntriesDeployer, beanPropertiesDeployer);
+                    try (final InputStream inputStream = new 
FileInputStream(file)) {
+                        parse(module, new InputSource(inputStream), 
envEntriesDeployer, beanPropertiesDeployer);
                     } catch (final ParserConfigurationException | IOException 
e) {
                         throw new SAXException(e);
                     }
                 } else { // try in the classpath
                     final ClassLoader cl = module.getClassLoader();
                     if (cl != null) {
-                        final InputStream is = cl.getResourceAsStream(path);
-                        if (is != null) {
-                            try {
-                                parse(module, new InputSource(is), 
envEntriesDeployer, beanPropertiesDeployer);
-                            } catch (final ParserConfigurationException | 
IOException e) {
-                                throw new SAXException(e);
+                        try (final InputStream is = 
cl.getResourceAsStream(path)) {
+                            if (is != null) {
+                                try {
+                                    parse(module, new InputSource(is), 
envEntriesDeployer, beanPropertiesDeployer);
+                                } catch (final ParserConfigurationException | 
IOException e) {
+                                    throw new SAXException(e);
+                                }
+                            } else {
+                                LOGGER.warning("Can't find " + path);
                             }
-                        } else {
-                            LOGGER.warning("Can't find " + path);
+                        } catch (final IOException e) {
+                            LOGGER.warning("Can't find " + path, e);
                         }
                     } else {
                         LOGGER.warning("Can't find " + path + ", no 
classloader for the module " + module);

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/core/managed/RAFPassivater.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/RAFPassivater.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/RAFPassivater.java
index 2b8348a..0827dcc 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/RAFPassivater.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/RAFPassivater.java
@@ -51,10 +51,10 @@ public class RAFPassivater implements PassivationStrategy {
 
     public synchronized void passivate(final Map stateTable)
         throws SystemException {
-        try {
+        try (final RandomAccessFile ras =
+                     new RandomAccessFile(System.getProperty("java.io.tmpdir", 
File.separator + "tmp") + File.separator + "passivation" + fileID + ".ser", 
"rw")) {
             fileID++;
 
-            final RandomAccessFile ras = new 
RandomAccessFile(System.getProperty("java.io.tmpdir", File.separator + "tmp") + 
File.separator + "passivation" + fileID + ".ser", "rw");
             final Iterator iterator = stateTable.keySet().iterator();
             Pointer lastPointer = null;
             while (iterator.hasNext()) {
@@ -72,7 +72,6 @@ public class RAFPassivater implements PassivationStrategy {
                 masterTable.put(id, lastPointer);
                 ras.write(bytes);
             }
-            ras.close();
         } catch (final Exception e) {
             throw new SystemException(e);
         }
@@ -86,9 +85,9 @@ public class RAFPassivater implements PassivationStrategy {
             return null;
         }
 
-        try {
-            final RandomAccessFile ras = new 
RandomAccessFile(System.getProperty("java.io.tmpdir", File.separator + "tmp") + 
File.separator + "passivation" + pointer.fileid + ".ser", "r");
-            final byte[] bytes = new byte[(int) pointer.bytesize];
+        try (final RandomAccessFile ras =
+                     new RandomAccessFile(System.getProperty("java.io.tmpdir", 
File.separator + "tmp") + File.separator + "passivation" + pointer.fileid + 
".ser", "r")) {
+            final byte[] bytes = new byte[pointer.bytesize];
             ras.seek(pointer.filepointer);
             ras.readFully(bytes);
             ras.close();

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
index 8360a16..40be8de 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
@@ -27,9 +27,11 @@ import org.apache.openejb.util.Logger;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.OutputStream;
 import java.util.Map;
 import java.util.Properties;
 
@@ -77,11 +79,12 @@ public class SimplePassivater implements 
PassivationStrategy {
             }
 
             logger.info("Passivating to file " + sessionFile);
-            final ObjectOutputStream oos = new 
ObjectOutputStream(IO.write(sessionFile));
-
-            oos.writeObject(state);// passivate just the bean instance
-            oos.close();
-            sessionFile.deleteOnExit();
+            try (final OutputStream os = IO.write(sessionFile);
+                 final ObjectOutputStream oos = new ObjectOutputStream(os)) {
+                oos.writeObject(state);// passivate just the bean instance
+            } finally {
+                sessionFile.deleteOnExit();
+            }
         } catch (final NotSerializableException nse) {
             logger.error("Passivation failed ", nse);
             throw (SystemException) new SystemException("The type " + 
nse.getMessage() + " is not serializable as mandated by the EJB 
specification.").initCause(nse);
@@ -108,13 +111,14 @@ public class SimplePassivater implements 
PassivationStrategy {
             if (sessionFile.exists()) {
                 logger.info("Activating from file " + sessionFile);
 
-                final ObjectInputStream ois = new 
ObjectInputStreamFiltered(IO.read(sessionFile));
-                final Object state = ois.readObject();
-                ois.close();
-                if (!sessionFile.delete()) {
-                    sessionFile.deleteOnExit();
+                try (final InputStream source = IO.read(sessionFile);
+                     final ObjectInputStream ois = new 
ObjectInputStreamFiltered(source)) {
+                    final Object state = ois.readObject();
+                    if (!sessionFile.delete()) {
+                        sessionFile.deleteOnExit();
+                    }
+                    return state;
                 }
-                return state;
             } else {
                 logger.info("Activation failed: file not found " + 
sessionFile);
                 return null;

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/RAFPassivater.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/RAFPassivater.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/RAFPassivater.java
index becc747..601fc7c 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/RAFPassivater.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/RAFPassivater.java
@@ -52,10 +52,10 @@ public class RAFPassivater implements PassivationStrategy {
     @Override
     public synchronized void passivate(final Map stateTable)
         throws SystemException {
-        try {
+        try(final RandomAccessFile ras = new RandomAccessFile(
+                System.getProperty("java.io.tmpdir", File.separator + "tmp") + 
File.separator + "passivation" + fileID + ".ser", "rw")) {
             fileID++;
 
-            final RandomAccessFile ras = new 
RandomAccessFile(System.getProperty("java.io.tmpdir", File.separator + "tmp") + 
File.separator + "passivation" + fileID + ".ser", "rw");
             final Iterator iterator = stateTable.keySet().iterator();
             Pointer lastPointer = null;
             while (iterator.hasNext()) {
@@ -73,7 +73,6 @@ public class RAFPassivater implements PassivationStrategy {
                 masterTable.put(id, lastPointer);
                 ras.write(bytes);
             }
-            ras.close();
         } catch (final Exception e) {
             throw new SystemException(e);
         }
@@ -88,12 +87,11 @@ public class RAFPassivater implements PassivationStrategy {
             return null;
         }
 
-        try {
-            final RandomAccessFile ras = new 
RandomAccessFile(System.getProperty("java.io.tmpdir", File.separator + "tmp") + 
File.separator + "passivation" + pointer.fileid + ".ser", "r");
-            final byte[] bytes = new byte[(int) pointer.bytesize];
+        try (final RandomAccessFile ras =
+                     new RandomAccessFile(System.getProperty("java.io.tmpdir", 
File.separator + "tmp") + File.separator + "passivation" + pointer.fileid + 
".ser", "r")) {
+            final byte[] bytes = new byte[pointer.bytesize];
             ras.seek(pointer.filepointer);
             ras.readFully(bytes);
-            ras.close();
             return Serializer.deserialize(bytes);
         } catch (final Exception e) {
             throw new SystemException(e);

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
index 3fba616..fdc7ebc 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
@@ -27,9 +27,11 @@ import org.apache.openejb.util.Logger;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.OutputStream;
 import java.util.Map;
 import java.util.Properties;
 
@@ -80,12 +82,11 @@ public class SimplePassivater implements 
PassivationStrategy {
 
             logger.info("Passivating to file " + sessionFile);
 
-            final ObjectOutputStream oos = new 
ObjectOutputStream(IO.write(sessionFile));
-            try {
+            try (final OutputStream os = IO.write(sessionFile);
+                 final ObjectOutputStream oos = new ObjectOutputStream(os)) {
                 oos.writeObject(state);// passivate just the bean instance
             } finally {
                 sessionFile.deleteOnExit();
-                IO.close(oos);
             }
 
         } catch (final NotSerializableException nse) {
@@ -114,11 +115,10 @@ public class SimplePassivater implements 
PassivationStrategy {
             if (sessionFile.exists()) {
                 logger.info("Activating from file " + sessionFile);
 
-                final ObjectInputStream ois = new 
EjbObjectInputStream(IO.read(sessionFile));
-                try {
+                try (final InputStream source = IO.read(sessionFile);
+                     final ObjectInputStream ois = new 
EjbObjectInputStream(source)) {
                     return ois.readObject();
                 } finally {
-                    IO.close(ois);
                     if (!sessionFile.delete()) {
                         sessionFile.deleteOnExit();
                     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
index 62edd00..b467092 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
@@ -464,9 +464,9 @@ public class ProviderWrapper extends Provider {
                     tempFile = File.createTempFile("openejb-jaxws-provider", 
"tmp", tmp);
                 }
                 tempFile.deleteOnExit();
-                final OutputStream out = IO.write(tempFile);
-                out.write(ProviderWrapper.class.getName().getBytes());
-                out.close();
+                try (final OutputStream out = IO.write(tempFile)) {
+                    out.write(ProviderWrapper.class.getName().getBytes());
+                }
                 PROVIDER_URL = tempFile.toURI().toURL();
             } catch (final IOException e) {
                 throw new OpenEJBRuntimeException("Cound not create 
openejb-jaxws-provider file");

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/service/ScanJarService.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/service/ScanJarService.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/service/ScanJarService.java
index 55bc62c..b175419 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/service/ScanJarService.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/service/ScanJarService.java
@@ -126,21 +126,21 @@ public class ScanJarService {
 
                     final File beansXml = new File(file, "META-INF/beans.xml");
                     if (beansXml.exists()) {
-                        final FileInputStream inputStream = new 
FileInputStream(beansXml);
-                        final Beans beansModel = 
ReadDescriptors.readBeans(inputStream);
-                        mergedModel.mergeClasses(url, beansModel);
-                        inputStream.close();
+                        try (final FileInputStream inputStream = new 
FileInputStream(beansXml)) {
+                            final Beans beansModel = 
ReadDescriptors.readBeans(inputStream);
+                            mergedModel.mergeClasses(url, beansModel);
+                        }
                     }
                 } else {
                     final FinderFactory.OpenEJBAnnotationFinder finder = new 
FinderFactory.OpenEJBAnnotationFinder(new JarArchive(loader, url));
                     mergedModel.getManagedClasses().put(url, 
finder.getAnnotatedClassNames());
 
                     try (final URLClassLoader cl = new URLClassLoader(new 
URL[]{ url })) {
-                        final InputStream is = 
cl.getResourceAsStream("META-INF/beans.xml");
-                        if (is != null) {
-                            final Beans beansModel = 
ReadDescriptors.readBeans(is);
-                            mergedModel.mergeClasses(url, beansModel);
-                            is.close();
+                        try (final InputStream is = 
cl.getResourceAsStream("META-INF/beans.xml")) {
+                            if (is != null) {
+                                final Beans beansModel = 
ReadDescriptors.readBeans(is);
+                                mergedModel.mergeClasses(url, beansModel);
+                            }
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/util/JarCreator.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/util/JarCreator.java 
b/container/openejb-core/src/main/java/org/apache/openejb/util/JarCreator.java
index 45bd836..04a1523 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/util/JarCreator.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/util/JarCreator.java
@@ -37,16 +37,19 @@ public final class JarCreator {
         final String[] entries = dir.list();
         final JarOutputStream out = new JarOutputStream(new 
FileOutputStream(zipName));
 
-        String prefix = dir.getAbsolutePath();
-        if (!prefix.endsWith(File.separator)) {
-            prefix += File.separator;
-        }
+        try {
+            String prefix = dir.getAbsolutePath();
+            if (!prefix.endsWith(File.separator)) {
+                prefix += File.separator;
+            }
 
-        for (final String entry : entries) {
-            final File f = new File(dir, entry);
-            jarFile(out, f, prefix);
+            for (final String entry : entries) {
+                final File f = new File(dir, entry);
+                jarFile(out, f, prefix);
+            }
+        } finally {
+            IO.close(out);
         }
-        IO.close(out);
     }
 
     private static void jarFile(final JarOutputStream out, final File f, final 
String prefix) throws IOException {
@@ -58,18 +61,18 @@ public final class JarCreator {
                 }
             }
         } else {
-            final byte[] buffer = new byte[BUFFER_SIZE];
-            int bytesRead;
-
             final String path = f.getPath().replace(prefix, "");
 
-            final FileInputStream in = new FileInputStream(f);
-            final JarEntry entry = new JarEntry(path);
-            out.putNextEntry(entry);
-            while ((bytesRead = in.read(buffer)) != -1) {
-                out.write(buffer, 0, bytesRead);
+            try (final FileInputStream in = new FileInputStream(f)) {
+                final JarEntry entry = new JarEntry(path);
+                out.putNextEntry(entry);
+
+                final byte[] buffer = new byte[BUFFER_SIZE];
+                int bytesRead;
+                while ((bytesRead = in.read(buffer)) != -1) {
+                    out.write(buffer, 0, bytesRead);
+                }
             }
-            IO.close(in);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
index e10a041..68e4339 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
@@ -149,15 +149,14 @@ public class UpdateChecker {
 
     public boolean usesLatest() {
         if (artifact().contains(TOMEE_ARTIFACT)) {
-            final InputStream is = 
getClass().getClassLoader().getResourceAsStream("META-INF/maven/org.apache.openejb/tomee-catalina/pom.properties");
-            if (is != null) {
-                final Properties prop = new Properties();
-                try {
+            try (final InputStream is = 
getClass().getClassLoader().getResourceAsStream("META-INF/maven/org.apache.openejb/tomee-catalina/pom.properties"))
 {
+                if (is != null) {
+                    final Properties prop = new Properties();
                     prop.load(is);
                     current = prop.getProperty("version");
-                } catch (final IOException e) {
-                    LOGGER.error("can't get tomee version, will use openejb 
one");
                 }
+            } catch (IOException e) {
+                LOGGER.error("can't get tomee version, will use openejb one");
             }
         }
 
@@ -177,9 +176,9 @@ public class UpdateChecker {
         if (current.equals(latest)) {
             return "running on the latest version";
         }
-        return new StringBuilder("you are using the version ").append(current)
-            .append(", our latest stable version ").append(latest)
-            .append(" is available on ").append(repoUrl).toString();
+        return "you are using the version " + current +
+                ", our latest stable version " + latest +
+                " is available on " + repoUrl;
     }
 
     public void setRepoUrl(final String repoUrl) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/a3402b52/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
 
b/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
index b03ec92..23a1951 100644
--- 
a/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
+++ 
b/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
@@ -198,9 +198,9 @@ public class MakeTxLookup implements Opcodes {
             file = new File(file, part);
         }
         file.getParentFile().mkdirs();
-        final FileOutputStream out = new FileOutputStream(file);
-        out.write(cw.toByteArray());
-        out.close();
+        try (final FileOutputStream out = new FileOutputStream(file)) {
+            out.write(cw.toByteArray());
+        }
     }
 
 }

Reply via email to