Enjoy the compression of RxJava 2 ( Flowable- backpressure support class):
public static Flowable<Path> listFolder(Path dir, String glob) {
return Flowable.using(
() -> Files.newDirectoryStream(dir, glob),
stream -> Flowable.fromIterable(stream),
stream -> stream.close());
}
If you do not want backpressure, replace Flowablewith Observable.
source
share