|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.io.StreamDrainerStoring
public class StreamDrainerStoring
StreamDrainer implementation that stores all bytes read from its InputStream.
This class is multithread safe: almost every method is synchronized.
The sole exception is run
, which internally synchronizes those code blocks which involve mutable state
using the same lock as the other methods (i.e. the instance itself).
Nested Class Summary | |
---|---|
static class |
StreamDrainerStoring.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private ByteArrayOutputStream |
baos
|
private static int |
baosSizeInitial
|
private static int |
bufferSize
|
private InputStream |
in
|
private Throwable |
throwable
|
Constructor Summary | |
---|---|
StreamDrainerStoring()
No-arg constructor. |
|
StreamDrainerStoring(InputStream in)
Constructor that calls init with in. |
Method Summary | |
---|---|
byte[] |
getBytes()
Returns all the bytes that have been drained by run
since the last time this method was called. |
Throwable |
getThrowable()
Returns any Throwable caught by run while it was draining that it could not handle. |
void |
init(InputStream in)
Assigns the InputStream that this instance must drain. |
void |
run()
Drains the InputStream supplied to init . |
private void |
setThrowable(Throwable throwable)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int baosSizeInitial
private static final int bufferSize
private InputStream in
private ByteArrayOutputStream baos
private Throwable throwable
Constructor Detail |
---|
public StreamDrainerStoring()
init
must be made before run
can be executed.
public StreamDrainerStoring(InputStream in) throws IllegalArgumentException
init
with in.
This is a convenience, because it relieves the user of having to make an additional call to init.
IllegalArgumentException
- if in is nullMethod Detail |
---|
public void init(InputStream in) throws IllegalArgumentException, IllegalStateException
StreamDrainer
Note that some implementations may have a constructor which takes an InputStream arg. In these cases, that constructor must call this method and the user should not subsequently call it again.
init
in interface StreamDrainer
IllegalArgumentException
- if in is null
IllegalStateException
- if called more than oncepublic void run() throws IllegalStateException
StreamDrainer
init
.
The fate of the drained bytes is implementation dependent (see getBytes
).
Other than the IllegalStateException described below,
this method guarantees to never throw any Throwable once draining has started.
Instead, if a Throwable is thrown that cannot be internally handled,
this method guarantees to store it for future retrieval by getThrowable
before aborting execution.
run
in interface StreamDrainer
run
in interface Runnable
IllegalStateException
- if init has not been called yet; this method is called more than oncepublic byte[] getBytes() throws IllegalStateException
run
since the last time this method was called.
Side effect: any stored bytes are cleared upon return.
getBytes
in interface StreamDrainer
IllegalStateException
- if run has never been calledpublic Throwable getThrowable() throws IllegalStateException
StreamDrainer
run
while it was draining that it could not handle.
getThrowable
in interface StreamDrainer
IllegalStateException
- if run has never been calledprivate void setThrowable(Throwable throwable)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |