Class TimeoutInputStream

java.lang.Object
java.io.InputStream
org.refcodes.io.TimeoutInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, org.refcodes.mixin.ReadTimeoutMillisAccessor
Direct Known Subclasses:
AvailableInputStream

public class TimeoutInputStream extends InputStream implements org.refcodes.mixin.ReadTimeoutMillisAccessor
The TimeoutInputStream decorates an InputStream with time-out functionality using CompletableFuture functionality. This decorator works despite the decorated InputStream returning realistic values when calling InputStream.available(). If this can be guaranteed, you may use the AvailableInputStream! The benefit of the AvailableInputStream over the TimeoutInputStream is that the AvailableInputStream does not use any additional threads for asynchronous operation! Additional thread is skipped in case the TimeoutInputStream timeout is -1 or the available (as of available()) number of bytes is greater or equal to the number of bytes to be read.