com.diasparsoftware.gsbase
Class StreamUtil

java.lang.Object
  extended bycom.diasparsoftware.gsbase.StreamUtil

public class StreamUtil
extends java.lang.Object

Provides some utility methods for working with streams.

Version:
$Revision: 1.1 $
Author:
J. B. Rainsberger

Constructor Summary
StreamUtil()
           
 
Method Summary
static byte[] flattenByteSegments(java.util.List byteSegments, int eachSegmentButLastLength, int lastSegmentLength)
          Turns a List of equally-sized byte segments (buffers) into a single buffer by concatenating them one by one.
static byte[] getContentAsBytes(java.io.InputStream byteStream)
          Reads the content coming from the specified input stream and presents it as an array of bytes.
static java.lang.String getContentAsString(java.io.InputStream characterStream)
          Reads the content coming from the specified input stream and presents it as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtil

public StreamUtil()
Method Detail

getContentAsString

public static java.lang.String getContentAsString(java.io.InputStream characterStream)
                                           throws java.io.IOException
Reads the content coming from the specified input stream and presents it as a string.

Returns:
A string representing the contents of the underlying stream
Throws:
java.io.IOException - Thrown by the underlying I/O operations

getContentAsBytes

public static byte[] getContentAsBytes(java.io.InputStream byteStream)
                                throws java.io.IOException
Reads the content coming from the specified input stream and presents it as an array of bytes.

Returns:
An array of bytes representing the contents of the underlying stream
Throws:
java.io.IOException - Thrown by the underlying I/O operations

flattenByteSegments

public static byte[] flattenByteSegments(java.util.List byteSegments,
                                         int eachSegmentButLastLength,
                                         int lastSegmentLength)
Turns a List of equally-sized byte segments (buffers) into a single buffer by concatenating them one by one.

Parameters:
byteSegments - The buffers to "flatten"
eachSegmentButLastLength - The length of each buffer but the last -- they are assumed all to be the same size
lastSegmentLength - The length of the last buffer, since it is likely not the same length as the others
Returns:


Copyright © 2003-2004 Diaspar Software Services, Inc.. All Rights Reserved.