Created
May 22, 2015 15:57
-
-
Save nsk-mironov/59c8015fbd0870232142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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