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
WriteCallbackthrows anIOException, any subsequent read from thisInputStreamwill throw anIOException, with the original appended to it.
Regarding the OutputStream provided to the WriteCallback:
- If this
InputStreamisclose()'ed, any subsequent write to theOutputStreamby theWriteCallbackwill generate anIOException.
- Since:
- 1.0.74
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionNullModemInputStream(WriteCallback writer, String threadName) Constructor that uses a background thread for writing.NullModemInputStream(WriteCallback writer, Executor executor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintprotected PipedStreamsGet thePipedStreamsassociated with this instance.intread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()longskip(long n) Methods inherited from class java.io.FilterInputStream
close, mark, markSupportedMethods 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 daemonThreadwith 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 bywriterto 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:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classFilterInputStream- Throws:
IOException
-
available
- Overrides:
availablein classFilterInputStream- Throws:
IOException
-
reset
- Overrides:
resetin classFilterInputStream- Throws:
IOException
-
getPipedStreams
Get thePipedStreamsassociated with this instance.- Returns:
- the underlying
PipedStreams
-