Java Scanners (and other classes) use buffering behind the scenes. Therefore, when experiencing unexpected blocking when using custom Java Input-/OutputStreams, additionally override the read(byte[], int, int)
and write(byte[], int, int)
methods along with their no-argument variants. Counter-intuitively, these may return less bytes than requested (but at least one), without blocking. However, the default implementation does not make use of that. Therefore, buffers use them to do non-blocking buffer reads.
Additionally, you might want to consider overriding flush()
and available()
, but these seem to be of lesser significance.