takeWhile is one of the functions provided by the protonpack library.
Stream infiniteInts = Stream.iterate(0, i -> i + 1);
Stream finiteInts = StreamUtils.takeWhile(infiniteInts, i -> i < 10);
assertThat(finiteInts.collect(Collectors.toList()),
hasSize(10));