diff options
author | Michael Bien <[email protected]> | 2011-09-13 17:55:21 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-09-13 17:55:21 +0200 |
commit | 3630d06bc4858ff82ea8cbe7b699fda211c0ec47 (patch) | |
tree | bed8c34703d2022c5c1e8ab8498584d2b8d77e65 | |
parent | a1545821e475736740953a02762c491f7c37cec7 (diff) |
extracted readStream utility method to CLUtil
-rw-r--r-- | src/com/jogamp/opencl/CLContext.java | 11 | ||||
-rw-r--r-- | src/com/jogamp/opencl/util/CLUtil.java | 27 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java index 45fdee64..771b594a 100644 --- a/src/com/jogamp/opencl/CLContext.java +++ b/src/com/jogamp/opencl/CLContext.java @@ -28,6 +28,7 @@ package com.jogamp.opencl; +import com.jogamp.opencl.util.CLUtil; import com.jogamp.opencl.llb.CL; import com.jogamp.common.nio.Buffers; import com.jogamp.opencl.CLDevice.Type; @@ -38,7 +39,6 @@ import com.jogamp.opencl.llb.CLContextBinding; import com.jogamp.opencl.llb.impl.CLImageFormatImpl; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.DoubleBuffer; @@ -284,14 +284,7 @@ public class CLContext extends CLObjectResource { char[] buffer = new char[1024]; for (InputStream source : sources) { - InputStreamReader reader = new InputStreamReader(source); - try { - int len = 0; - while ((len = reader.read(buffer)) != -1) - sb.append(buffer, 0, len); - } finally { - reader.close(); - } + CLUtil.readStream(source, sb, buffer); } return createProgram(sb); diff --git a/src/com/jogamp/opencl/util/CLUtil.java b/src/com/jogamp/opencl/util/CLUtil.java index 98a6cd7e..ff04f745 100644 --- a/src/com/jogamp/opencl/util/CLUtil.java +++ b/src/com/jogamp/opencl/util/CLUtil.java @@ -33,6 +33,9 @@ import com.jogamp.opencl.llb.CL; import com.jogamp.opencl.CLDevice; import com.jogamp.opencl.CLPlatform; import com.jogamp.opencl.CLProperty; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -82,6 +85,30 @@ public class CLUtil { } /** + * Reads chars from input stream and puts them into the supplied StringBuilder. + * The stream is closed after successful or unsuccessful read. + */ + public static StringBuilder readStream(InputStream source, StringBuilder dest) throws IOException { + return readStream(source, dest, new char[1024]); + } + + /** + * Reads chars from input stream and puts them into the supplied StringBuilder using the supplied buffer. + * The stream is closed after successful or unsuccessful read. + */ + public static StringBuilder readStream(InputStream source, StringBuilder dest, char[] buffer) throws IOException { + InputStreamReader reader = new InputStreamReader(source); + try { + int len = 0; + while ((len = reader.read(buffer)) != -1) + dest.append(buffer, 0, len); + } finally { + reader.close(); + } + return dest; + } + + /** * Reads all platform properties and returns them as key-value map. */ public static Map<String, String> obtainPlatformProperties(CLPlatform platform) { |