- java.lang.Object
-
- java.io.InputStream
-
- org.refcodes.io.SkipAvailableInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Skippable
,org.refcodes.mixin.ReadTimeoutInMsAccessor
public class SkipAvailableInputStream extends InputStream implements org.refcodes.mixin.ReadTimeoutInMsAccessor, Skippable
TheSkipAvailableInputStream
decorates anInputStream
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)
orSkippable.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 theavailable()
method to return some useful information!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.ReadTimeoutInMsAccessor
org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsBuilder<B extends org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsBuilder<B>>, org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsMutator, org.refcodes.mixin.ReadTimeoutInMsAccessor.ReadTimeoutInMsProperty
-
-
Constructor Summary
Constructors Constructor Description SkipAvailableInputStream(InputStream aInputStream)
Constructs aSkipAvailableInputStream
decorating anInputStream
with additional timeout functionality.SkipAvailableInputStream(InputStream aInputStream, long aTimeoutInMs)
Constructs aSkipAvailableInputStream
decorating anInputStream
with additional timeout functionality.
-
Method Summary
All Methods Instance Methods Concrete Methods 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)
-
Methods inherited from class java.io.InputStream
nullInputStream, readNBytes
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.io.Skippable
skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableWithin
-
-
-
-
Constructor Detail
-
SkipAvailableInputStream
public SkipAvailableInputStream(InputStream aInputStream)
Constructs aSkipAvailableInputStream
decorating anInputStream
with additional timeout functionality.- Parameters:
aInputStream
- TheInputStream
to be decorated.
-
SkipAvailableInputStream
public SkipAvailableInputStream(InputStream aInputStream, long aTimeoutInMs)
Constructs aSkipAvailableInputStream
decorating anInputStream
with additional timeout functionality.- Parameters:
aInputStream
- TheInputStream
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).
-
-
Method Detail
-
skipAvailableTillSilenceFor
public void skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs) throws IOException, org.refcodes.exception.TimeoutIOException
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. This method blocks until the time span of silence has been reached. ATTENTION: To apply a custom timeout, please useSkippable.skipAvailableTillSilenceFor(long, long)
. In case the read timeout as ofgetReadTimeoutInMs()
) is not -1 and the overall time while skipping bytes exceeds the read timeout aTimeoutIOException
is thrown. ATTENTION: To apply a custom timeout, please useSkippable.skipAvailableTillSilenceFor(long, long)
.- Specified by:
skipAvailableTillSilenceFor
in interfaceSkippable
- Parameters:
aSilenceTimeSpanInMs
- The time span in milliseconds of silence (0 bytes available) till skipping is terminated.- Throws:
org.refcodes.exception.TimeoutIOException
- in case the the read timeout is not -1 as ofgetReadTimeoutInMs()
and the overall time while skipping bytes exceeds the read timeout .IOException
- thrown in case of I/O issues.
-
skipAvailableWithin
public void skipAvailableWithin(long aSkipTimeSpanInMs) throws IOException
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. ATTENTION: To apply a custom timeout, please useSkippable.skipAvailableWithin(long, long)
. In case the read timeout as ofgetReadTimeoutInMs()
) is not -1 and the overall time while skipping bytes exceeds the read timeout aTimeoutIOException
is thrown. ATTENTION: To apply a custom timeout, please useSkippable.skipAvailableWithin(long, long)
.- Specified by:
skipAvailableWithin
in interfaceSkippable
- Parameters:
aSkipTimeSpanInMs
- the skip time span in ms- Throws:
org.refcodes.exception.TimeoutIOException
- in case the the read timeout is not -1 as ofgetReadTimeoutInMs()
and the overall time while skipping bytes exceeds the read timeout .IOException
- thrown in case of I/O issues.
-
available
public int available() throws IOException
- Specified by:
available
in interfaceSkippable
- Overrides:
available
in classInputStream
- Throws:
IOException
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] aB, int aOff, int aLen) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] aB) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
readAllBytes
public byte[] readAllBytes() throws IOException
- Overrides:
readAllBytes
in classInputStream
- Throws:
IOException
-
readNBytes
public int readNBytes(byte[] b, int off, int len) throws IOException
- Overrides:
readNBytes
in classInputStream
- Throws:
IOException
-
transferTo
public long transferTo(OutputStream aOut) throws IOException
- Overrides:
transferTo
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
-
reset
public void reset() throws IOException
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
public long skip(long n) throws IOException
- Specified by:
skip
in interfaceSkippable
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
getReadTimeoutInMs
public long getReadTimeoutInMs()
- Specified by:
getReadTimeoutInMs
in interfaceorg.refcodes.mixin.ReadTimeoutInMsAccessor
-
-