Closeable
, AutoCloseable
, Skippable
, org.refcodes.mixin.ReadTimeoutInMsAccessor
public class SkipAvailableInputStream extends InputStream implements org.refcodes.mixin.ReadTimeoutInMsAccessor, Skippable
SkipAvailableInputStream
decorates an InputStream
with
skip timed functionality, e.g. skip all currently available bytes
(Skippable.skipAvailable()
), all bytes available for a period of time
(skipAvailableWithin(long)
) or skip all bytes available till a send
pause of a given time is detected (skipAvailableTillSilenceFor(long)
or Skippable.skipAvailableTillSilenceFor(long, long)
). Especially the latter
two methods are useful when a send pause is used by some kind of handshake
mechanism. ATTENTION: This implementation relies upon the
available()
method to return some useful information!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 |
---|---|
SkipAvailableInputStream(InputStream aInputStream) |
Constructs a
SkipAvailableInputStream decorating an
InputStream with additional timeout functionality. |
SkipAvailableInputStream(InputStream aInputStream,
long aTimeoutInMs) |
Constructs a
SkipAvailableInputStream 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[] aB) |
|
int |
read(byte[] aB,
int aOff,
int aLen) |
|
byte[] |
readAllBytes() |
|
int |
readNBytes(byte[] b,
int off,
int len) |
|
void |
reset() |
|
long |
skip(long n) |
|
void |
skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs) |
Skips all available bytes till a given time span of silence is detected:
The number of bytes available must be 0 for the given time span for this
operation to conclude.
|
void |
skipAvailableWithin(long aSkipTimeSpanInMs) |
Skips all available bytes till after the given time no more bytes are
available, else skipping is repeated till no more bytes are available
within the given time span.This method blocks until the according
available bytes have been skipped.
|
String |
toString() |
|
long |
transferTo(OutputStream aOut) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableWithin
public SkipAvailableInputStream(InputStream aInputStream)
SkipAvailableInputStream
decorating an
InputStream
with additional timeout functionality.aInputStream
- The InputStream
to be decorated.public SkipAvailableInputStream(InputStream aInputStream, long aTimeoutInMs)
SkipAvailableInputStream
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 void skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs) throws IOException, org.refcodes.exception.TimeoutIoException
Skippable.skipAvailableTillSilenceFor(long, long)
. In case the read timeout as of
getReadTimeoutInMs()
) is not -1 and the overall time while
skipping bytes exceeds the read timeout a TimeoutIoException
is
thrown. ATTENTION: To apply a custom timeout, please use
Skippable.skipAvailableTillSilenceFor(long, long)
.skipAvailableTillSilenceFor
in interface Skippable
aSilenceTimeSpanInMs
- The time span in milliseconds of silence (0
bytes available) till skipping is terminated.org.refcodes.exception.TimeoutIoException
- in case the the read timeout is not -1 as of
getReadTimeoutInMs()
and the overall time while skipping
bytes exceeds the read timeout .IOException
- thrown in case of I/O issues.public void skipAvailableWithin(long aSkipTimeSpanInMs) throws IOException
Skippable.skipAvailableWithin(long, long)
. In case the read timeout as of
getReadTimeoutInMs()
) is not -1 and the overall time while
skipping bytes exceeds the read timeout a TimeoutIoException
is
thrown. ATTENTION: To apply a custom timeout, please use
Skippable.skipAvailableWithin(long, long)
.skipAvailableWithin
in interface Skippable
aSkipTimeSpanInMs
- the skip time span in msorg.refcodes.exception.TimeoutIoException
- in case the the read timeout is not -1 as of
getReadTimeoutInMs()
and the overall time while skipping
bytes exceeds the read timeout .IOException
- thrown in case of I/O issues.public int available() throws IOException
available
in interface Skippable
available
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] aB, int aOff, int aLen) throws IOException
read
in class InputStream
IOException
public int read(byte[] aB) throws IOException
read
in class InputStream
IOException
public byte[] readAllBytes() throws IOException
readAllBytes
in class InputStream
IOException
public int readNBytes(byte[] b, int off, int len) throws IOException
readNBytes
in class InputStream
IOException
public long transferTo(OutputStream aOut) throws IOException
transferTo
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 interface Skippable
skip
in class InputStream
IOException
public long getReadTimeoutInMs()
getReadTimeoutInMs
in interface org.refcodes.mixin.ReadTimeoutInMsAccessor
Copyright © 2021. All rights reserved.