While it is possible to convert a DirectoryStream
into a Stream
using its spliterator
method, there is no reason to do so. Just create a Stream<Path>
in the first place.
E.g., instead of calling Files.newDirectoryStream(Path)
just call Files.list(Path)
.
The overload of newDirectoryStream
which accepts an additional Filter
may be replaced by Files.list(Path).filter(Predicate)
and there are additional operations like Files.find
and Files.walk
returning a Stream<Path>
, however, I did not find a replacement for the case you want to use the “glob pattern”. That seems to be the only case where translating a DirectoryStream
into a Stream
might be useful (I prefer using regular expressions anyway)…