0
私はrx javaをRetrofit、okhttpと一緒に使っています。 ソケットが閉じた例外android
のようなさまざまな方法で試してみました「ソケットクローズ」を取得した入力sreamを読みながら、コンテンツをダウンロードした後: * onNext方法、そして読んで、入力ストリームからの応答を取得
私のコードは次のようになります。
mApi.getPdf(mUserManager.getUserProfile().getAuthToken())
.compose(mRxUtils.applySchedulers())
.subscribe(new Subscriber<ResponseBody>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
mApiErrorManager.handleError(e);
}
@Override
public void onNext(ResponseBody downloadPDFModelResponse) {
downloadFile(downloadPDFModelResponse, myFile);
}
});
ダウンロード機能は、次のようになります。
private void downloadFile(ResponseBody body, File myFile) throws IOException {
int count;
byte data[] = new byte[1024 * 4];
long fileSize = body.contentLength();
InputStream bis = new BufferedInputStream(body.byteStream(), 1024 * 8);
File outputFile = myFile;
OutputStream output = new FileOutputStream(outputFile);
long total = 0;
long startTime = System.currentTimeMillis();
//int timeCount = 1;
while ((count = bis.read(data)) != -1) { //here getting Socket closed exception
total += count;
int progress = (int) ((total * 100)/fileSize);
mEventBus.post(new DownloadProgress(progress));
output.write(data, 0, count);
}
mEventBus.post(new DownloadProgress(DownloadProgress.COMPLETE));
output.flush();
output.close();
bis.close();
}
を改造するには、「読み入力ストリーム」とはどういう意味ですか?あなたの入力ストリームは何ですか?あなたはどんなエラーを出していますか? – degs
あなたはlogcatでいくつかのコードを投稿できますか? – JediBurrell
これはあなたを助けるでしょう: [あなたのans](http://stackoverflow.com/a/8840042) –