June 2015
Intermediate to advanced
182 pages
3h 56m
English
Here is one interesting example:
Path path = Paths.get("src", "main", "resources");
Observable<String> data = CreateObservable
.listFolder(path, "*")
.flatMap(file -> {
if (!Files.isDirectory(file)) {
return CreateObservable
.from(file)
.subscribeOn(Schedulers.io());
}
return Observable.empty();
});
subscribePrint(data, "Too many lines");This goes through all the files in a folder and reads all of them in parallel if they are not folders themselves. For the example, while I'm running it, there are five text files in the folder, and one of them is quite large. While printing the content of these files with our subscribePrint() method, we get something that looks like this:
Too many lines : Morbi nec nulla ipsum. ...Read now
Unlock full access