Revision: 2423 http://vexi.svn.sourceforge.net/vexi/?rev=2423&view=rev Author: mkpg2 Date: 2007-10-10 01:05:57 -0700 (Wed, 10 Oct 2007)
Log Message: ----------- IOUtil class for reusable functions dealing with streams (replaces InputStreamToByteArray ...). Added Paths: ----------- trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java Removed Paths: ------------- trunk/core/org.ibex.util/src/org/ibex/util/InputStreamToByteArray.java Added: trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java =================================================================== --- trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java (rev 0) +++ trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java 2007-10-10 08:05:57 UTC (rev 2423) @@ -0,0 +1,42 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + +package org.ibex.util; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/* wanted to call this IOU ... */ +public class IOUtil { + + /** scratch space for isToByteArray() */ + private static byte[] workspace = new byte[16 * 1024]; + + /** Trivial method to completely read an InputStream */ + public static synchronized byte[] toByteArray(InputStream is) throws IOException { + int pos = 0; + while (true) { + int numread = is.read(workspace, pos, workspace.length - pos); + if (numread == -1) break; + else if (pos + numread < workspace.length) pos += numread; + else { + pos += numread; + byte[] temp = new byte[workspace.length * 2]; + System.arraycopy(workspace, 0, temp, 0, workspace.length); + workspace = temp; + } + } + byte[] ret = new byte[pos]; + System.arraycopy(workspace, 0, ret, 0, pos); + return ret; + } + + public static synchronized void pipe(InputStream in, OutputStream out) throws IOException { + while (true) { + int bytesRead = in.read(workspace); + if (bytesRead == -1) break; + out.write(workspace, 0, bytesRead); + } + } +} Property changes on: trunk/core/org.ibex.util/src/org/ibex/util/IOUtil.java ___________________________________________________________________ Name: svn:mime-type + text/plain Deleted: trunk/core/org.ibex.util/src/org/ibex/util/InputStreamToByteArray.java =================================================================== --- trunk/core/org.ibex.util/src/org/ibex/util/InputStreamToByteArray.java 2007-10-09 17:24:50 UTC (rev 2422) +++ trunk/core/org.ibex.util/src/org/ibex/util/InputStreamToByteArray.java 2007-10-10 08:05:57 UTC (rev 2423) @@ -1,33 +0,0 @@ -// Copyright 2000-2005 the Contributors, as shown in the revision logs. -// Licensed under the Apache Public Source License 2.0 ("the License"). -// You may not use this file except in compliance with the License. - -package org.ibex.util; -import java.io.IOException; -import java.io.InputStream; - -public class InputStreamToByteArray { - - /** scratch space for isToByteArray() */ - private static byte[] workspace = new byte[16 * 1024]; - - /** Trivial method to completely read an InputStream */ - public static synchronized byte[] convert(InputStream is) throws IOException { - int pos = 0; - while (true) { - int numread = is.read(workspace, pos, workspace.length - pos); - if (numread == -1) break; - else if (pos + numread < workspace.length) pos += numread; - else { - pos += numread; - byte[] temp = new byte[workspace.length * 2]; - System.arraycopy(workspace, 0, temp, 0, workspace.length); - workspace = temp; - } - } - byte[] ret = new byte[pos]; - System.arraycopy(workspace, 0, ret, 0, pos); - return ret; - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn