|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.core.util.stream.StreamUtil
public class StreamUtil
Provides some utilities to work on streams and some (de)serialization methods..
| Method Summary | |
|---|---|
static long |
copy(InputStream input,
OutputStream output)
Copies data from the input stream to the output stream. |
static long |
copy(InputStream input,
OutputStream output,
boolean closeStreams)
Copies data from the input stream to the output stream. |
static long |
copy(InputStream input,
OutputStream output,
long startByte,
long length)
Copies data from the input stream to the output stream. |
static long |
copy(Reader rdr,
Writer wrt)
Equivalent of copy(InputStream, OutputStream) but using reader and writer instead
of streams. |
static long |
copy(Reader rdr,
Writer wrt,
boolean closeStreams)
Equivalent of copy(InputStream, OutputStream, boolean) only using reader and writer
instead of input stream and output stream. |
static Object |
deserialize(byte[] serializedData)
Deserializes the given serialization data and returns the object. |
static void |
safeClose(Closeable stream)
Can be used to safely close a stream. |
static byte[] |
serialize(Serializable object)
Given a serializable object, this will return the object's serialized byte array representation. |
static byte[] |
slurp(InputStream stream)
Reads in the entire contents of the given input stream and returns the data in a byte array. |
static String |
slurp(Reader reader)
Equivalent of slurp(InputStream) but using a reader instead of input stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static byte[] slurp(InputStream stream)
throws RuntimeException
OutOfMemoryError.
stream - the stream to read
RuntimeException - if an IO exception occurred while reading the stream
public static String slurp(Reader reader)
throws RuntimeException
slurp(InputStream) but using a reader instead of input stream.
reader -
RuntimeException
public static long copy(InputStream input,
OutputStream output)
throws RuntimeException
input - the originating stream that contains the data to be copiedoutput - the destination stream where the data should be copied to
RuntimeException - if failed to read or write the data
public static long copy(Reader rdr,
Writer wrt)
throws RuntimeException
copy(InputStream, OutputStream) but using reader and writer instead
of streams.
rdr - wrt -
RuntimeException
public static long copy(InputStream input,
OutputStream output,
boolean closeStreams)
throws RuntimeException
closeStreams is true. If closeStreams is
false, the streams are left open; the caller has the responsibility to close them.
input - the originating stream that contains the data to be copiedoutput - the destination stream where the data should be copied tocloseStreams - if true, the streams will be closed before the method returns
RuntimeException - if failed to read or write the data
public static long copy(Reader rdr,
Writer wrt,
boolean closeStreams)
throws RuntimeException
copy(InputStream, OutputStream, boolean) only using reader and writer
instead of input stream and output stream.
rdr - wrt - closeStreams -
RuntimeException
public static long copy(InputStream input,
OutputStream output,
long startByte,
long length)
throws RuntimeException
length indicates how many bytes to copy, a
negative length indicates copy everything up to the EOF of the input stream.
Because this method must leave the given input stream intact in case the caller wants to continue reading from
the input stream (that is, in case the caller wants to read the next byte after the final byte read by this
method), this method will not wrap the input stream with a buffered input stream. Because of this, this method is
less efficient than copy(InputStream, OutputStream, boolean). If you do not care to continue reading
from the input stream after this method completes, it is recommended you wrap your input stream in a
BufferedInputStream and pass that buffered stream to this method.
input - the originating stream that contains the data to be copiedoutput - the destination stream where the data should be copied tostartByte - the first byte to copy from the input stream (byte indexes start at #0)length - the number of bytes to copy - if -1, then copy all until EOF
input after the start byte, this return value will be less than
length.
RuntimeException - if failed to read or write the data
public static byte[] serialize(Serializable object)
throws RuntimeException
object - the object to serialize
RuntimeException - if failed to serialize the object
public static Object deserialize(byte[] serializedData)
throws RuntimeException
serializedData - the serialized data as a byte array
RuntimeException - if failed to deserialize the objectpublic static void safeClose(Closeable stream)
stream - the stream to close or null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||