public class StreamTools
extends java.lang.Object
InputStream and OutputStream related tool methods.| Constructor and Description |
|---|
StreamTools() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends java.io.Serializable> |
cloneViaByteArray(java.io.Serializable object,
java.lang.Class<T> clazz)
Clone the designated object by converting it to a byte array with
toByteArray(Serializable) and deserialise it again with fromByteArray(byte[]). |
static byte[] |
copyStreamToByteArray(java.io.InputStream in)
Copy all content of the given InputStream to a new byte array.
|
static void |
copyStreamToStream(java.io.InputStream in,
java.io.OutputStream out)
Copy all content of the given InputStream to the given OutputStream.
|
static java.io.Serializable |
fromByteArray(byte[] object)
Deserialises the object contained in the designated byte array.
|
static byte[] |
toByteArray(java.io.Serializable object)
Converts the designated serialisable object to a byte array.
|
public static void copyStreamToStream(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - input streamout - output streamjava.io.IOException - if an I/O error occurspublic static byte[] copyStreamToByteArray(java.io.InputStream in)
throws java.io.IOException
in - input streamjava.io.IOException - if an I/O error occurspublic static final byte[] toByteArray(java.io.Serializable object)
throws java.io.IOException
object - A serialisable object to convert to a byte array.java.io.IOException - If there are problems when writing the designated
object, a IOException will be thrown.public static final java.io.Serializable fromByteArray(byte[] object)
throws java.io.IOException,
java.lang.ClassNotFoundException
object - A byte array representing a serialised object.java.io.IOException - If there are problems when reading from the designated
byte array, a IOException will be thrown.java.lang.ClassNotFoundException - If the class of the designated object cannot
be found for deserialisation, a
ClassNotFoundException will be thrown.public static final <T extends java.io.Serializable> T cloneViaByteArray(java.io.Serializable object,
java.lang.Class<T> clazz)
throws java.io.IOException,
java.lang.ClassNotFoundException
toByteArray(Serializable) and deserialise it again with fromByteArray(byte[]).object - A serialisable object to be copied.clazz - The class of the serialisable object.java.io.IOException - If there are problems when writing the designated object or reading from
the designated byte array, an IOException will be thrown.java.lang.ClassNotFoundException - If the class of the designated object cannot be found for
deserialisation, a ClassNotFoundException will be thrown.