Skip to content

Instantly share code, notes, and snippets.

@nsk-mironov
Created May 22, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsk-mironov/59c8015fbd0870232142 to your computer and use it in GitHub Desktop.
Save nsk-mironov/59c8015fbd0870232142 to your computer and use it in GitHub Desktop.
public Observable<Response> upload(final Image image) {
// create new ArrayList in case if image.getChunks() returns immutable collection
final List<Chunk> chunks = new ArrayList<Chunk>(image.getChunks());
if (chunks.isEmpty()) {
return Observable.empty();
}
if (chunks.size() == 1) {
return api.upload(chunks.get(0));
}
final Observable<Response> first = api.upload(chunks.get(0));
final Observable<Response> last = api.upload(chunks.get(chunks.size() - 1));
chunks.remove(chunks.size() - 1);
chunks.remove(0);
return first.concat(chunks.flatMap(chunk -> return api.upload(chunk))).concat(last);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment