Closeable
, AutoCloseable
, org.refcodes.mixin.ReadTimeoutInMsAccessor
TimeoutInputStream.DummyTimeoutInputStream
public class TimeoutInputStream extends InputStream implements org.refcodes.mixin.ReadTimeoutInMsAccessor
TimeoutInputStream
decorates an InputStream
with time-out
functionality. To avoid performance issues due to exhausting synchronization,
this class is not thread safe (take care of synchronizing yourself when
accessing from multiple threads). This decorator works only when the
decorated InputStream
returns realistic values when calling
InputStream.available()
.Modifier and Type | Class | Description |
---|---|---|
static class |
TimeoutInputStream.DummyTimeoutInputStream |
Dummy implementation of a
TimeoutInputStream directly delegating
to the given InputStream to test whether the
TimeoutInputStream has any latencies compared to the
TimeoutInputStream.DummyTimeoutInputStream . |
org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsBuilder<B extends org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsBuilder<B>>, org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsMutator, org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsProperty
Constructor | Description |
---|---|
TimeoutInputStream(InputStream aInputStream) |
Constructs a
TimeoutInputStream decorating an InputStream
with additional timeout functionality. |
TimeoutInputStream(InputStream aInputStream,
long aTimeoutInMs) |
Constructs a
TimeoutInputStream decorating an InputStream
with additional timeout functionality. |
TimeoutInputStream(InputStream aInputStream,
long aTimeoutInMs,
Object aMonitor) |
Constructs a
TimeoutInputStream decorating an InputStream
with additional timeout functionality. |
TimeoutInputStream(InputStream aInputStream,
Object aMonitor) |
Constructs a
TimeoutInputStream decorating an InputStream
with additional timeout functionality. |
Modifier and Type | Method | Description |
---|---|---|
int |
available() |
|
void |
close() |
|
long |
getReadTimeoutInMs() |
|
void |
mark(int readlimit) |
|
boolean |
markSupported() |
|
int |
read() |
|
int |
read(byte[] b) |
|
int |
read(byte[] b,
int off,
int len) |
|
int |
read(byte[] b,
int off,
int len,
long aTimeoutInMs) |
Enriches the
read(byte[], int, int) method with a timeout. |
int |
read(byte[] b,
long aTimeoutInMs) |
Enriches the
read(byte[]) method with a timeout. |
int |
read(long aTimeoutInMs) |
Enriches the
read() method with a timeout. |
int |
readNBytes(byte[] b,
int off,
int len) |
|
int |
readNBytes(byte[] b,
int off,
int len,
long aTimeoutInMs) |
Enriches the
readNBytes(byte[], int, int) method with a timeout. |
void |
reset() |
|
long |
skip(long n) |
readAllBytes, transferTo
public TimeoutInputStream(InputStream aInputStream, long aTimeoutInMs)
TimeoutInputStream
decorating an InputStream
with additional timeout functionality.aInputStream
- The InputStream
to be decorated.aTimeoutInMs
- The default timeout for read operations not
explicitly called with a timeout argument. With a value of -1
timeout handling is disabled (blocking mode).public TimeoutInputStream(InputStream aInputStream, Object aMonitor)
TimeoutInputStream
decorating an InputStream
with additional timeout functionality.aInputStream
- The InputStream
to be decorated.aMonitor
- The monitor to use when waiting the poll loop time. This
is useful required available data can be read before the poll loop
time expires. E.g. an underlying system might call
Object.notifyAll()
on the monitor as soon as it received
new data.public TimeoutInputStream(InputStream aInputStream)
TimeoutInputStream
decorating an InputStream
with additional timeout functionality.aInputStream
- The InputStream
to be decorated.public TimeoutInputStream(InputStream aInputStream, long aTimeoutInMs, Object aMonitor)
TimeoutInputStream
decorating an InputStream
with additional timeout functionality.aInputStream
- The InputStream
to be decorated.aTimeoutInMs
- The default timeout for read operations not
explicitly called with a timeout argument. With a value of -1
timeout handling is disabled (blocking mode).aMonitor
- The monitor to use when waiting the poll loop time. This
is useful required available data can be read before the poll loop
time expires. E.g. an underlying system might call
Object.notifyAll()
on the monitor as soon as it received
new data.public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public int read(byte[] b) throws IOException
read
in class InputStream
IOException
public int readNBytes(byte[] b, int off, int len) throws IOException
readNBytes
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
close
in class InputStream
IOException
public void mark(int readlimit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public int read(long aTimeoutInMs) throws IOException
read()
method with a timeout. This methods blocks
till the result is available and can be returned or the timeout is
reached. A timeout of -1 disables the timeout.aTimeoutInMs
- The timeout in milliseconds to wait for the next byte
available.With a value of -1 timeout handling is disabled
(blocking mode).IOException
- thrown in case of according I/O related problems or
an expired timeout.public int read(byte[] b, int off, int len, long aTimeoutInMs) throws IOException
read(byte[], int, int)
method with a timeout. This
methods blocks till the result is available and can be returned or the
timeout is reached. A timeout of -1 disables the timeout.b
- The byte array into which the data is read.off
- The start offset in b at which the data is written.len
- The maximum number of bytes to read.aTimeoutInMs
- The timeout in milliseconds to wait for the next byte
available.With a value of -1 timeout handling is disabled
(blocking mode).IOException
- thrown in case of according I/O related problems or
an expired timeout.public int read(byte[] b, long aTimeoutInMs) throws IOException
read(byte[])
method with a timeout. This methods
blocks till the result is available and can be returned or the timeout is
reached. A timeout of -1 disables the timeout. Calling this method has
the same effect a read(b, 0, b.length)
, so we try to read as
many bytes as the buffer's length is.b
- The byte array into which the data is read.aTimeoutInMs
- The timeout in milliseconds to wait for the next byte
available.With a value of -1 timeout handling is disabled
(blocking mode).IOException
- thrown in case of according I/O related problems or
an expired timeout.public int readNBytes(byte[] b, int off, int len, long aTimeoutInMs) throws IOException
readNBytes(byte[], int, int)
method with a timeout.
This methods blocks till the result is available and can be returned or
the timeout is reached. A timeout of -1 disables the timeout.b
- the boff
- the offlen
- the lenaTimeoutInMs
- the timeout in msIOException
- Signals that an I/O exception has occurred.public long getReadTimeoutInMs()
getReadTimeoutInMs
in interface org.refcodes.mixin.ReadTimeoutInMsAccessor
Copyright © 2021. All rights reserved.