Created
June 24, 2016 08:03
-
-
Save shts/47dd80ad2f2b53706e4bb74743fbd459 to your computer and use it in GitHub Desktop.
RxJavaでファイルダウンロード
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 class Download { | |
public Observable<File> download(List<String> target) { | |
return Observable.from(target) | |
.map(new Func1<String, okhttp3.Request>() { | |
@Override | |
public okhttp3.Request call(String url) { | |
return new Request.Builder().url(url).build(); | |
} | |
}) | |
.map(new Func1<Request, File>() { | |
@Override | |
public File call(Request request) { | |
try { | |
okhttp3.Response response = | |
new OkHttpClient.Builder().build().newCall(request).execute(); | |
if (!response.isSuccessful()) throw new IOException(""); | |
Bitmap bitmap = BitmapFactory.decodeStream(response.body().byteStream()); | |
// TODO: bitmap into file | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment