Search in sources :

Example 1 with HttpResult

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);
}
Also used : HttpHeader(com.xiaoyunchengzhu.httpapi.net.HttpHeader) Headers(okhttp3.Headers) HttpResult(com.xiaoyunchengzhu.httpapi.net.HttpResult)

Example 2 with 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);
            }
        });
    }
}
Also used : HttpResult(com.xiaoyunchengzhu.httpapi.net.HttpResult) HttpApi(com.xiaoyunchengzhu.httpapi.http.HttpApi) HttpApi(com.xiaoyunchengzhu.httpapi.http.HttpApi) Api(com.xiaoyunchengzhu.httpapi.net.Api) DownLoadCallBackResult(com.xiaoyunchengzhu.httpapi.net.DownLoadCallBackResult)

Aggregations

HttpResult (com.xiaoyunchengzhu.httpapi.net.HttpResult)2 HttpApi (com.xiaoyunchengzhu.httpapi.http.HttpApi)1 Api (com.xiaoyunchengzhu.httpapi.net.Api)1 DownLoadCallBackResult (com.xiaoyunchengzhu.httpapi.net.DownLoadCallBackResult)1 HttpHeader (com.xiaoyunchengzhu.httpapi.net.HttpHeader)1 Headers (okhttp3.Headers)1