diff options
author | Sven Gothel <[email protected]> | 2012-03-10 03:32:29 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-03-10 03:32:29 +0100 |
commit | 24f8694a188b4a5255d4ac4f8b49982bd8ad3228 (patch) | |
tree | 1856155e530640b666a1d0a8574c851244eb9e22 /src/java/com/jogamp/common/util/IOUtil.java | |
parent | 227ad20f6bf10d5d28073dfbd3fac363e3a09531 (diff) |
Stabilize open InputStream's / Closeable's: Decorate w/ try-finally and close within the latter
Diffstat (limited to 'src/java/com/jogamp/common/util/IOUtil.java')
-rw-r--r-- | src/java/com/jogamp/common/util/IOUtil.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 9e803cb..0463c37 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -30,6 +30,7 @@ package com.jogamp.common.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -585,4 +586,19 @@ public class IOUtil { } throw new IOException("Could not create temp directory @ "+tempRoot.getAbsolutePath()+tmpDirPrefix+"_*"); } + + public static void close(Closeable stream, boolean throwRuntimeException) throws RuntimeException { + if(null != stream) { + try { + stream.close(); + } catch (IOException e) { + if(throwRuntimeException) { + throw new RuntimeException(e); + } else if(DEBUG) { + System.err.println("Catched Exception: "); + e.printStackTrace(); + } + } + } + } } |