|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
net.sf.zig_project.gpl.common.io.ThreadedTransfer
The ThreadedTransfer class delegates IO operations to independant threads. This may result in a significant reduction in time required for a transfer to complete, as IO operations are scheduled concurrently, if possible.
The ideal use for this class is to transfer data from an InputStream to an OutputStream where the speed of each stream is roughly comparable to that of it's counterpart. Further, this class is also ideal for mirroring data across several OutputStreams, as this will attempt to mirror concurrently, instead of sequentially.
Each instance of ThreadedTransfer maintains a single shared buffer. Blocking will only occur when either the buffer is full, or enforce the ordering of writes to that buffer.
Notice: Every instance of this class must either be aborted or closed! Otherwise, active threads will continue to wait for further input data, and resources will neither be garbage collected nor finalized.
Field Summary | |
static byte |
ABORTED
|
static byte |
CLOSED
|
int |
frame_size
|
static byte |
OPEN
|
ThreadGroup |
threads
The threads object represents a control over the internal threads spawned by addOutput and addInput. |
Constructor Summary | |
ThreadedTransfer(String desc)
|
|
ThreadedTransfer(String desc,
int frame_sz)
|
|
ThreadedTransfer(String desc,
int frame_len,
int frame_count)
|
Method Summary | |
void |
abort()
Aborts the current ThreadedTransfer. |
void |
addOutput(OutputStream out,
IOExceptionHandler eh)
Adds out to the set of OutputStreams to which write and slurp operations will be mirrored. |
void |
close()
Forces all previously added streams to close. |
void |
destroy()
Ensures that this Transfer is safely terminated. |
void |
flush()
Forces all output sources to perform a flush operation. |
byte |
getState()
Allows polling of the state of the Transfer. |
void |
slurp(InputStream in)
Uses the currently executing thread to load data from the selected InputStream and load it into the buffers for the OutputStream set. |
void |
write(byte[] buf,
int off,
int len)
Writes data to all underlying OutputStreams. |
void |
write(int i)
Writes a single byte of data to all underlying OutputStreams. |
Methods inherited from class java.io.OutputStream |
write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public final int frame_size
public final ThreadGroup threads
Use with caution.
public static final byte OPEN
public static final byte ABORTED
public static final byte CLOSED
Constructor Detail |
public ThreadedTransfer(String desc)
public ThreadedTransfer(String desc, int frame_sz)
public ThreadedTransfer(String desc, int frame_len, int frame_count)
Method Detail |
public void slurp(InputStream in) throws IOException
Transfer.transfer(InputStream, OutputStream)
since the provided
InputStream is read to exhaustion, it is automatically closed before
this method returns.
IOException
public void addOutput(OutputStream out, IOExceptionHandler eh)
public void flush() throws IOException
InterruptedIOException
- if the current thread was interrupted
while waiting for all streams to flush
IOException
- if the stream was not open when this call was madepublic void close() throws InterruptedIOException
InterruptedIOException
- if the current thread was interrupted
while waiting for all streams to closepublic byte getState()
public void write(byte[] buf, int off, int len) throws IOException
InterruptedIOException
- if the current thread was
interrupted while waiting for more room in the internal
buffer
IOException
- if no OutputStreams are currently
active in this transferpublic void write(int i) throws IOException
InterruptedIOException
- if the current thread was
interrupted while waiting for room in the buffer to
become available
IOException
- if no OutputStreams are currently
active in this transferpublic void abort()
public void destroy()
finally
clause to ensure the instance has met some
end and can be recollected.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |