Edit: removed Observable.create, the modification already makes it visible to you, you just need to convert it.
Edit 2: you also do not need to do anything with the .onError subscriber; if an error is selected, it will itself call the subscriber.onError function.
Pretty good, Not sure why you went with the plane observed. Instead, I would make a flatmap for Observable :: from, and it's worth adding as well. Basically, I am going to display one thing for many, then take some action, put it back a lot, and then subscribe to it when I have collected all the emitted elements.
public static Observable<DownloadedFiles> downloadFiles() { return getRestService().getObjectList() .flatMap(Observable::from) .flatMap(objectLimited -> getRestService().getObject(objectLimited.getPath())) .doOnNext(objectFull -> { try { File file = new File(); // Extract data from objectFull and write new file to disk // ... } catch (IOException e) { new IOException(e); }}) .collect(() -> new DownloadFiles<>(), (files, object) -> { files.add(object});
source share