diff options
author | Sven Gothel <[email protected]> | 2012-03-10 03:38:35 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-03-10 03:38:35 +0100 |
commit | beadbb27530b75507ffa8d56a204b1a59a7bda0d (patch) | |
tree | 28c66dec9b8e79004fbf1818b4c8a070c18af349 /src/jogl/classes/com/jogamp | |
parent | d28e1b139f14b10b9e22750ac44dbc18f08a0d34 (diff) |
Stabilize open InputStream's / Closeable's: Decorate w/ try-finally and close within the latter
See gluegen commit 24f8694a188b4a5255d4ac4f8b49982bd8ad3228
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java index 85e288638..eec055ed4 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -295,39 +295,43 @@ public class ShaderCode { } } - private static int readShaderSource(Class<?> context, URL url, StringBuffer result, int lineno) { + private static int readShaderSource(Class<?> context, URL url, StringBuffer result, int lineno) { try { if(DEBUG_CODE) { System.err.printf("%3d: // %s\n", lineno, url); } - BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); - String line = null; - while ((line = reader.readLine()) != null) { - lineno++; - if(DEBUG_CODE) { - System.err.printf("%3d: %s\n", lineno, line); - } - if (line.startsWith("#include ")) { - String includeFile = line.substring(9).trim(); - URL nextURL = null; - - // Try relative path first - String next = IOUtil.getRelativeOf(url, includeFile); - if(null != next) { - nextURL = IOUtil.getResource(context, next); - } - if (nextURL == null) { - // Try absolute path - nextURL = IOUtil.getResource(context, includeFile); + final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); + try { + String line = null; + while ((line = reader.readLine()) != null) { + lineno++; + if(DEBUG_CODE) { + System.err.printf("%3d: %s\n", lineno, line); } - if (nextURL == null) { - // Fail - throw new FileNotFoundException("Can't find include file " + includeFile); + if (line.startsWith("#include ")) { + String includeFile = line.substring(9).trim(); + URL nextURL = null; + + // Try relative path first + String next = IOUtil.getRelativeOf(url, includeFile); + if(null != next) { + nextURL = IOUtil.getResource(context, next); + } + if (nextURL == null) { + // Try absolute path + nextURL = IOUtil.getResource(context, includeFile); + } + if (nextURL == null) { + // Fail + throw new FileNotFoundException("Can't find include file " + includeFile); + } + lineno = readShaderSource(context, nextURL, result, lineno); + } else { + result.append(line + "\n"); } - lineno = readShaderSource(context, nextURL, result, lineno); - } else { - result.append(line + "\n"); } + } finally { + IOUtil.close(reader, false); } } catch (IOException e) { throw new RuntimeException(e); @@ -358,12 +362,17 @@ public class ShaderCode { } public static ByteBuffer readShaderBinary(Class<?> context, String path) { + final URL url = IOUtil.getResource(context, path); + if (url == null) { + return null; + } try { - URL url = IOUtil.getResource(context, path); - if (url == null) { - return null; + final BufferedInputStream bis = new BufferedInputStream( url.openStream() ); + try { + return IOUtil.copyStream2ByteBuffer( bis ); + } finally { + IOUtil.close(bis, false); } - return IOUtil.copyStream2ByteBuffer( new BufferedInputStream( url.openStream() ) ); } catch (IOException e) { throw new RuntimeException(e); } |