net.lucidviews.util.io
Class Streams

java.lang.Object
  extended by net.lucidviews.util.io.Streams
Direct Known Subclasses:
Files

public class Streams
extends Object

A collection of methods for manipualting data Streams.

Since:
1.0
Version:
$Revision: 1.2 $
Author:
Stephen Battey

Field Summary
protected static int DEFAULT_BUFFER_SIZE
          the default buffer size used to pipe data across I/O streams
 
Constructor Summary
protected Streams()
          Suppresses default constructor, ensuring non-instantiability.
 
Method Summary
static void close(InputStream stream)
          Close an input stream.
static void close(OutputStream stream)
          Close an output stream.
static boolean compare(InputStream stream1, InputStream stream2)
          Compare the content of two streams to determine if the data in both streams is the same.
static boolean compare(InputStream stream1, InputStream stream2, int bufferSize)
          Compare the content of two streams to determine if the data in both streams is the same.
static void pipe(InputStream in, OutputStream out)
          Pipe data across I/O streams.
static void pipe(InputStream in, OutputStream out, int bufferSize)
          Pipe data across I/O streams.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

protected static final int DEFAULT_BUFFER_SIZE
the default buffer size used to pipe data across I/O streams

See Also:
Constant Field Values
Constructor Detail

Streams

protected Streams()
Suppresses default constructor, ensuring non-instantiability.

Method Detail

pipe

public static void pipe(InputStream in,
                        OutputStream out)
                 throws IOException
Pipe data across I/O streams.
The transfer will take place using a data-buffer of default size.

Parameters:
in - the input stream
out - the output stream
Throws:
IOException - error reading or writing data

pipe

public static void pipe(InputStream in,
                        OutputStream out,
                        int bufferSize)
                 throws IOException
Pipe data across I/O streams.
The transfer will take place using a data-buffer of the specified size.

Parameters:
in - the input stream
out - the output stream
bufferSize - the size of the data buffer
Throws:
IOException - error reading or writing data

close

public static void close(InputStream stream)
Close an input stream.
If the stream is null then this method has no action. Any exception caused by closing the stream is silently handled.

Parameters:
stream - the stream to be closed

close

public static void close(OutputStream stream)
Close an output stream.
If the stream is null then this method has no action. Any exception caused by closing the stream is silently handled.

Parameters:
stream - the stream to be closed

compare

public static boolean compare(InputStream stream1,
                              InputStream stream2)
                       throws IOException
Compare the content of two streams to determine if the data in both streams is the same.
The comparison will be performed using a data-buffer of the specified size.

Once the comparison is completed, both streams will be closed.

Parameters:
stream1 - a stream to be compared to the second stream
stream2 - a stream to be compared to the first stream
Returns:
true if the binary content of both streams match exactly
Throws:
IOException - error reading data from the streams

compare

public static boolean compare(InputStream stream1,
                              InputStream stream2,
                              int bufferSize)
                       throws IOException
Compare the content of two streams to determine if the data in both streams is the same.

The comparison will be performed using a data-buffer of the specified size.

Once the comparison is completed, both streams will be closed.

Parameters:
stream1 - a stream to be compared to the second stream
stream2 - a stream to be compared to the first stream
bufferSize - the size of the data buffer used when comparing binary data
Returns:
true if the binary content of both streams match exactly
Throws:
IOException - error reading data from the streams