libbluray | branch: master | ace20022 <[email protected]> | Fri Nov 28 12:22:06 2014 +0100| [3d2236f883ab41406bc7ea0d1643a3b5ed83bf9d] | committer: ace20022
[fix][java] Close resources in MountManager in case of an exception. > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=3d2236f883ab41406bc7ea0d1643a3b5ed83bf9d --- .../bdj/java/org/videolan/MountManager.java | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libbluray/bdj/java/org/videolan/MountManager.java b/src/libbluray/bdj/java/org/videolan/MountManager.java index 75a2333..a3feff7 100644 --- a/src/libbluray/bdj/java/org/videolan/MountManager.java +++ b/src/libbluray/bdj/java/org/videolan/MountManager.java @@ -86,6 +86,8 @@ public class MountManager { throw new MountException(); } + InputStream inStream = null; + OutputStream outStream = null; try { byte[] buffer = new byte[32 * 1024]; Enumeration entries = jar.entries(); @@ -103,8 +105,8 @@ public class MountManager { logger.info(" mount: " + entry.getName()); - InputStream inStream = jar.getInputStream(entry); - OutputStream outStream = new FileOutputStream(out); + inStream = jar.getInputStream(entry); + outStream = new FileOutputStream(out); int length; while ((length = inStream.read(buffer)) > 0) { @@ -119,6 +121,26 @@ public class MountManager { e.printStackTrace(); mountPoint.remove(); throw new MountException(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (outStream != null) { + try { + outStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + jar.close(); + } catch (IOException e) { + e.printStackTrace(); + } } if (mountPoint.classFiles() != classFiles) { _______________________________________________ libbluray-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libbluray-devel
