use of com.xiaoyunchengzhu.httpapi.net.HttpResult in project HttpApiDemo by xiaoyunchengzhu.
the class OkhttpCallbackAdapter method onResponse.
@Override
public void onResponse(Call call, final Response response) {
HttpResult httpResult = new HttpResult();
httpResult.setInputStream(response.body().byteStream());
httpResult.setContentLength(response.body().contentLength());
HttpHeader httpHeader = new HttpHeader();
Headers headers = response.headers();
for (String name : headers.names()) {
httpHeader.put(name, headers.get(name));
}
httpResult.setHttpHeader(httpHeader);
httpResult.setProtocol(response.protocol().name());
httpResult.setResponseCode(response.code());
httpResult.setUrl(api.getUrl());
callBackResult.success(api, httpResult);
}
use of com.xiaoyunchengzhu.httpapi.net.HttpResult in project HttpApiDemo by xiaoyunchengzhu.
the class DownloadUtil method addtask.
public void addtask(final List<DonloadInfo> query) {
for (final DonloadInfo donloadInfo : query) {
APIManager.createApi(new HttpApi(donloadInfo.getUrl())).head("Range", donloadInfo.getCurrentIndedx() + "-" + donloadInfo.getEndIndex()).execute(new CallBackResult<HttpResult>() {
@Override
public void success(Api api, HttpResult result) {
donwload(donloadInfo, result.getInputStream(), api, new DownLoadCallBackResult(donloadInfo.getFilPath()) {
@Override
public void success(Api api, String result) {
completcount += 1;
if (completcount == query.size()) {
downLoadCallBackResult.success(api, result);
}
}
@Override
public void failure(Api api, String error) {
downLoadCallBackResult.failure(api, error);
}
@Override
public void onDownloadProgress(long currentSize, long totalSize, double progress) {
downloadcurentSize += currentSize;
downLoadCallBackResult.onDownloadProgress(downloadcurentSize, donloadInfo.getContentLength(), (double) downloadcurentSize / donloadInfo.getContentLength());
LogManger.i("下载 ---" + downloadcurentSize);
}
});
}
@Override
public void failure(Api api, String error) {
downLoadCallBackResult.failure(api, error);
}
@Override
public void onDownloadProgress(long currentSize, long totalSize, double progress) {
downLoadCallBackResult.onDownloadProgress(downloadcurentSize, donloadInfo.getContentLength(), (double) downloadcurentSize / donloadInfo.getContentLength());
}
@Override
public void onUpLoadProgress(long currentSize, long totalSize, double progress) {
downLoadCallBackResult.onUpLoadProgress(currentSize, totalSize, progress);
}
});
}
}
Aggregations