org.ops4j.io
Class StreamUtils

java.lang.Object
  extended by org.ops4j.io.StreamUtils

public final class StreamUtils
extends java.lang.Object

Version:
$Id: StreamUtils.java 3769 2006-03-25 01:32:43Z niclas@hedhman.org $
Author:
Open Particpation Software for Java

Method Summary
static boolean compareStreams(java.io.InputStream in1, java.io.InputStream in2)
          Compares if two streams are identical in their contents.
static void copyReaderToStream(java.io.Reader in, java.io.OutputStream out, java.lang.String encoding, boolean close)
          Copies the content of the Reader to the provided OutputStream using the provided encoding.
static void copyReaderToWriter(java.io.Reader input, java.io.Writer output, boolean close)
          Copies the Reader to the Writer.
static void copyStream(java.io.InputStream src, java.io.OutputStream dest, boolean closeStreams)
          Copy a stream.
static void copyStream(StreamMonitor monitor, java.net.URL sourceURL, int expected, java.io.InputStream source, java.io.OutputStream destination, boolean closeStreams)
          Copy a stream.
static void copyStreamToWriter(java.io.InputStream in, java.io.Writer out, java.lang.String encoding, boolean close)
          Copies an InputStream to a Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyStream

public static void copyStream(java.io.InputStream src,
                              java.io.OutputStream dest,
                              boolean closeStreams)
                       throws java.io.IOException,
                              NullArgumentException
Copy a stream.

Parameters:
src - the source input stream
dest - the destination output stream
closeStreams - TRUE if the streams should be closed on completion
Throws:
java.io.IOException - if an IO error occurs
NullArgumentException - if either the src or dest arguments are null.

copyStream

public static void copyStream(StreamMonitor monitor,
                              java.net.URL sourceURL,
                              int expected,
                              java.io.InputStream source,
                              java.io.OutputStream destination,
                              boolean closeStreams)
                       throws java.io.IOException,
                              NullArgumentException
Copy a stream.

Parameters:
sourceURL - the source url
expected - the expected size in bytes
source - the source input stream
destination - the destination output stream
closeStreams - TRUE if the streams should be closed on completion
monitor - The StreamMonitor to report progress to.
Throws:
java.io.IOException - if an IO error occurs
NullArgumentException - if either the src or dest arguments are null.

compareStreams

public static boolean compareStreams(java.io.InputStream in1,
                                     java.io.InputStream in2)
                              throws java.io.IOException
Compares if two streams are identical in their contents.

Parameters:
in1 - The first stream.
in2 - The second stream.
Returns:
true if both streams contains the same byte data, including having the same number of characters in them.
Throws:
java.io.IOException - If an underlying I/O problem occured.

copyReaderToWriter

public static void copyReaderToWriter(java.io.Reader input,
                                      java.io.Writer output,
                                      boolean close)
                               throws java.io.IOException
Copies the Reader to the Writer.

Parameters:
input - The input characters.
output - The destination of the characters.
close - true if the reader and writer should be closed after the operation is completed.
Throws:
java.io.IOException - If an underlying I/O problem occured.

copyStreamToWriter

public static void copyStreamToWriter(java.io.InputStream in,
                                      java.io.Writer out,
                                      java.lang.String encoding,
                                      boolean close)
                               throws java.io.IOException
Copies an InputStream to a Writer.

Parameters:
in - The input byte stream of data.
out - The Writer to receive the streamed data as characters.
encoding - The encoding used in the byte stream.
close - true if the Reader and OutputStream should be closed after the completion.
Throws:
java.io.IOException - If an underlying I/O Exception occurs.

copyReaderToStream

public static void copyReaderToStream(java.io.Reader in,
                                      java.io.OutputStream out,
                                      java.lang.String encoding,
                                      boolean close)
                               throws java.io.IOException
Copies the content of the Reader to the provided OutputStream using the provided encoding.

Parameters:
in - The character data to convert.
out - The OutputStream to send the data to.
encoding - The character encoding that should be used for the byte stream.
close - true if the Reader and OutputStream should be closed after the completion.
Throws:
java.io.IOException - If an underlying I/O Exception occurs.


Copyright © 2006-2008 OPS4J - Open Participation Software for Java. All Rights Reserved.