Class AvailableInputStream

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

public class AvailableInputStream extends TimeoutInputStream
The AvailableInputStream decorates an InputStream with time-out functionality using the InputStream.available() method. This decorator works only when the decorated InputStream returns realistic values when calling InputStream.available(). This is most probably the case e.g. for serial communication (TTY/COM) as those devices usually buffer for incoming bytes. If this cannot be guaranteed, please use the TimeoutInputStream! The benefit of the AvailableInputStream over the TimeoutInputStream is that the AvailableInputStream does not use any additional threads for asynchronous operation so it is a good fit for IoT devices!