Package org.dellroad.stuff.io
Class NullModemInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.dellroad.stuff.io.NullModemInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Presents an
InputStream
interface given a WriteCallback
that can write to an OutputStream
.
A background process, initated by a provided Executor
, invokes the WriteCallback
to write
to an OutputStream
that relays whatever is written to this InputStream
.
Exceptions
Regarding this InputStream
:
- If the
WriteCallback
throws anIOException
, any subsequent read from thisInputStream
will throw anIOException
, with the original appended to it.
Regarding the OutputStream
provided to the WriteCallback
:
- If this
InputStream
isclose()
'ed, any subsequent write to theOutputStream
by theWriteCallback
will generate anIOException
.
- Since:
- 1.0.74
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionNullModemInputStream
(WriteCallback writer, String threadName) Constructor that uses a background thread for writing.NullModemInputStream
(WriteCallback writer, Executor executor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionint
protected PipedStreams
Get thePipedStreams
associated with this instance.int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) void
reset()
long
skip
(long n) Methods inherited from class java.io.FilterInputStream
close, mark, markSupported
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
NullModemInputStream
Constructor that uses a background thread for writing.Delegates to
NullModemInputStream(WriteCallback, Executor)
, passing an executor that creates a dedicated daemonThread
with the given name.- Parameters:
writer
- callback that writes the data to be readthreadName
- name for the background thread to be created
-
NullModemInputStream
Constructor.The
writer
'swriteTo()
method will be invoked (once) asynchronously in a dedicated writer thread. This instance will produce whatever data is written bywriter
to the providedOutputStream
.- Parameters:
writer
- callback that writes the data to be readexecutor
- executes writing process in the background- Throws:
IllegalArgumentException
- if any parameter is null
-
-
Method Details
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classFilterInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classFilterInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
-
getPipedStreams
Get thePipedStreams
associated with this instance.- Returns:
- the underlying
PipedStreams
-