|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.yajul.io.StreamCopier
public class StreamCopier
Provides stream copying capability in a Runnable class. This can be used to
redirect streams from a spawned JVM, or to 'pump' a one side of
PipedInputStream / PipedOutputStream pair.
Also provides a static method that copies an entire input stream into
an output stream.
Field Summary | |
---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size. |
Constructor Summary | |
---|---|
StreamCopier(java.io.InputStream in,
java.io.OutputStream out)
Creates a new stream copier, that will copy the input stream into the output stream when the run() method is caled. |
Method Summary | |
---|---|
static int |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copies the input stream into the output stream in a thread safe and efficient manner. |
static int |
copy(java.io.InputStream in,
java.io.OutputStream out,
int bufsz)
Copies the input stream into the output stream in a thread safe and efficient manner. |
java.io.IOException |
getException()
Returns the exception thrown in the run() method, if any. |
boolean |
isComplete()
Returns true if the copying is complete. |
static java.util.ArrayList |
readBlocks(java.io.InputStream in,
int blocksz)
Reads the entire input stream into an array list of byte arrays, each byte array being a maximum of 'blocksz' bytes long. |
static byte[] |
readByteArray(java.io.File file)
Reads the specified file into a byte array. |
static byte[] |
readByteArray(java.io.InputStream in)
Reads the entire input stream into a byte array. |
static byte[] |
readByteArray(java.io.InputStream in,
int limit)
Reads the entire input stream into a byte array with a limit. |
static byte[] |
readByteArray(java.io.Reader in)
Reads the entire input stream into a byte array. |
static byte[] |
readByteArray(java.io.Reader in,
int limit)
Reads the entire input stream into a byte array with a limit. |
static byte[] |
readFileIntoByteArray(java.lang.String fileName)
Reads the specified file into a byte array. |
void |
run()
This method will copy the input into the output until there is no more input. |
static byte[] |
serializeObject(java.lang.Object o)
Serializes the object into an array of bytes. |
static java.lang.Object |
unserializeObject(byte[] bytes)
Reads a serialized object from the array of bytes. |
static int |
unsyncCopy(java.io.InputStream in,
java.io.OutputStream out,
int bufsz)
Copies the input stream into the output stream in an efficient manner. |
static int |
unsyncCopy(java.io.InputStream in,
java.io.OutputStream out,
int bufsz,
int limit)
Copies the input stream into the output stream in an efficient manner. |
static int |
unsyncCopy(java.io.Reader in,
java.io.Writer out,
int bufsz,
int limit)
Copies the input stream (reader) into the output stream (writer) in an efficient manner. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_BUFFER_SIZE
Constructor Detail |
---|
public StreamCopier(java.io.InputStream in, java.io.OutputStream out)
in
- The input stream to read from.out
- The output stream. If this is null, the input will be
discarded, similar to piping to /dev/null on UN*X.Method Detail |
---|
public static int copy(java.io.InputStream in, java.io.OutputStream out, int bufsz) throws java.io.IOException
in
- The input stream.out
- The output stream. If this is null, the input will be
discarded, similar to piping to /dev/null on UN*X.bufsz
- The size of the buffer to use.
java.io.IOException
- When the stream could not be copied.public static int unsyncCopy(java.io.InputStream in, java.io.OutputStream out, int bufsz) throws java.io.IOException
in
- The input stream.out
- The output stream. If this is null, the input will be
discarded, similar to piping to /dev/null on UN*X.bufsz
- The size of the buffer to use.
java.io.IOException
- When the stream could not be copied.public static int unsyncCopy(java.io.InputStream in, java.io.OutputStream out, int bufsz, int limit) throws java.io.IOException
in
- The input stream.out
- The output stream. If this is null, the input will be
discarded, similar to piping to /dev/null on UN*X.bufsz
- The size of the buffer to use.limit
- The number of bytes to copy, or UNLIMITED (-1) to copy
until the end of the input stream.
java.io.IOException
- When the stream could not be copied.public static int unsyncCopy(java.io.Reader in, java.io.Writer out, int bufsz, int limit) throws java.io.IOException
in
- The input readerout
- The output writer. If this is null, the input will be
discarded, similar to piping to /dev/null on UN*X.bufsz
- The size of the buffer to use.limit
- The number of bytes to copy, or UNLIMITED (-1) to copy
until the end of the input stream.
java.io.IOException
- When the stream could not be copied.public static int copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- The input stream.out
- The output stream. If this is null, the input will be
discarded, similar to piping to /dev/null on UN*X.
java.io.IOException
- When the stream could not be copied.public static java.util.ArrayList readBlocks(java.io.InputStream in, int blocksz) throws java.io.IOException
blocksz
- The block size. Byte arrays in the list will not
be longer than this.in
- The input stream.
java.io.IOException
- When something happens while reading the stream.public static byte[] readByteArray(java.io.InputStream in) throws java.io.IOException
in
- The input stream.
java.io.IOException
- When something happens while reading the stream.public static byte[] readByteArray(java.io.InputStream in, int limit) throws java.io.IOException
in
- The input readerlimit
- The number of bytes to read.
java.io.IOException
- Thrown if there was an error while copying.public static byte[] readByteArray(java.io.Reader in, int limit) throws java.io.IOException
in
- The input readerlimit
- The number of bytes to read.
java.io.IOException
- Thrown if there was an error while copying.public static byte[] readByteArray(java.io.Reader in) throws java.io.IOException
in
- The input reader
java.io.IOException
- Thrown if there was an error while copying.public static byte[] readByteArray(java.io.File file) throws java.io.IOException
file
- The file to read.
java.io.IOException
- When something happens while reading the stream.public static byte[] readFileIntoByteArray(java.lang.String fileName) throws java.io.IOException
fileName
- The file name to read.
java.io.IOException
- When something happens while reading the stream.public static byte[] serializeObject(java.lang.Object o) throws java.io.IOException
o
- The object to serialize.
java.io.IOException
- if something goes wrongpublic static java.lang.Object unserializeObject(byte[] bytes) throws java.io.IOException, java.lang.ClassNotFoundException
bytes
- The array of bytes.
java.io.IOException
- if there was a problem reading the input.
java.lang.ClassNotFoundException
- if the class of the object in the input was not found.public void run()
Runnable
is used
to create a thread, starting the thread causes the object's
run
method to be called in that separately executing
thread.
The general contract of the method run
is that it may
take any action whatsoever.
run
in interface java.lang.Runnable
Thread.run()
public java.io.IOException getException()
public boolean isComplete()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |