com.mockrunner.util.common
Class StreamUtil

java.lang.Object
  extended by com.mockrunner.util.common.StreamUtil

public class StreamUtil
extends java.lang.Object

Simple util class for manipulating streams


Constructor Summary
StreamUtil()
           
 
Method Summary
static boolean compareReaders(java.io.Reader sourceReader, java.io.Reader targetReader)
          Compares the content of the readers.
static boolean compareStreams(java.io.InputStream sourceStream, java.io.InputStream targetStream)
          Compares the content of the streams.
static java.io.Reader copyReader(java.io.Reader sourceReader)
          Returns a copy of the specified reader.
static java.io.InputStream copyStream(java.io.InputStream sourceStream)
          Returns a copy of the specified stream.
static java.util.List getLinesFromReader(java.io.Reader reader)
          Reads the lines from the specified reader and adds them to a List.
static java.lang.String getReaderAsString(java.io.Reader reader)
          Returns the contents of the reader as a string.
static java.lang.String getReaderAsString(java.io.Reader reader, int length)
          Returns the contents of the reader as a string.
static byte[] getStreamAsByteArray(java.io.InputStream stream)
          Returns the contents of the input stream as byte array.
static byte[] getStreamAsByteArray(java.io.InputStream stream, int length)
          Returns the contents of the input stream as byte array.
 
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

getStreamAsByteArray

public static byte[] getStreamAsByteArray(java.io.InputStream stream)
Returns the contents of the input stream as byte array.

Parameters:
stream - the InputStream
Returns:
the stream content as byte array

getStreamAsByteArray

public static byte[] getStreamAsByteArray(java.io.InputStream stream,
                                          int length)
Returns the contents of the input stream as byte array.

Parameters:
stream - the InputStream
length - the number of bytes to copy, if length < 0, the number is unlimited
Returns:
the stream content as byte array

getReaderAsString

public static java.lang.String getReaderAsString(java.io.Reader reader)
Returns the contents of the reader as a string.

Parameters:
reader - the Reader
Returns:
the reader content as String

getReaderAsString

public static java.lang.String getReaderAsString(java.io.Reader reader,
                                                 int length)
Returns the contents of the reader as a string.

Parameters:
reader - the Reader
length - the number of chars to copy, if length < 0, the number is unlimited
Returns:
the reader content as String

copyStream

public static java.io.InputStream copyStream(java.io.InputStream sourceStream)
Returns a copy of the specified stream. If the specified stream supports marking, it will be reset after the copy.

Parameters:
sourceStream - the stream to copy
Returns:
a copy of the stream

copyReader

public static java.io.Reader copyReader(java.io.Reader sourceReader)
Returns a copy of the specified reader. If the specified reader supports marking, it will be reset after the copy.

Parameters:
sourceReader - the stream to reader
Returns:
a copy of the reader

compareStreams

public static boolean compareStreams(java.io.InputStream sourceStream,
                                     java.io.InputStream targetStream)
Compares the content of the streams. If the streams support marking, they will be reset after the comparison.

Parameters:
sourceStream - the source stream
targetStream - the target stream
Returns:
true, if the streams are identical, false otherwise

compareReaders

public static boolean compareReaders(java.io.Reader sourceReader,
                                     java.io.Reader targetReader)
Compares the content of the readers. If the readers support marking, they will be reset after the comparison.

Parameters:
sourceReader - the source stream
targetReader - the target stream
Returns:
true, if the streams are identical, false otherwise

getLinesFromReader

public static java.util.List getLinesFromReader(java.io.Reader reader)
Reads the lines from the specified reader and adds them to a List.

Parameters:
reader - the reader
Returns:
the List with the lines