java – Terminate a Stream when there is no incoming Data after a certain Timeout

EDIT: My original answer (below) operated at the readLine() level, but on second thoughts it can be nicer to operate on the Stream level. Here is an approach that operates on Streams. The core function is takeUntilTime(Stream<T> stream, Instant end), and the rest are small helpers. The idea is to traverse the original stream using … Read more