From 24f8694a188b4a5255d4ac4f8b49982bd8ad3228 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 10 Mar 2012 03:32:29 +0100 Subject: Stabilize open InputStream's / Closeable's: Decorate w/ try-finally and close within the latter --- src/java/com/jogamp/common/util/IOUtil.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/java/com/jogamp/common/util/IOUtil.java') 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(); + } + } + } + } } -- cgit v1.2.3