public class RevivableInputStream
extends java.io.InputStream
.read
calls by calling .kill
. Reading from the
stream can be resumed by calling .resurrect
.
The common use for this is to avoid closing an input stream, while still be
able to cancel a blocking .read
where you must use an input
stream. This is useful if you need to send a message to the thread which
attempts to read from the input stream.
com.hypirion.io 0.1.0
Constructor and Description |
---|
RevivableInputStream(java.io.InputStream in)
Creates a new
RevivableInputStream which wraps
in , giving it power to be killed and resurrected. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes than can be read from this input stream
without blocking.
|
void |
close()
Closes this revivable input stream and the underlying input stream, and
releases any with system resources (threads, memory) associated with this
stream.
|
void |
kill()
Kills this revivable input stream.
|
int |
read()
Reads the next byte of data from this revivable input stream.
|
int |
read(byte[] b,
int off,
int len) |
void |
resurrect()
Resurrects a killed revivable input stream.
|
public RevivableInputStream(java.io.InputStream in)
RevivableInputStream
which wraps
in
, giving it power to be killed and resurrected.public int available()
available
in class java.io.InputStream
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- if the underlying InputStream
throws
an IOException
.public int read() throws java.io.IOException
int
in the range 0
to
255
. This method blocks until no data is available, the end
of the stream is detected, an exception is thrown or if the reviable
input stream is (potentially temporarily) killed.read
in class java.io.InputStream
-1
if the end of the
stream is reached or the stream is killed.java.io.IOException
- if the underlying InputStream
throws
an IOException
when attempted to read. This exception will
be thrown every time read is called until the stream is closed.public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public void kill()
resurrect()
. If this revivable input stream is already killed,
this method does nothing.resurrect()
public void resurrect()
kill()