当前位置: 首页>>代码示例>>Java>>正文


Java Headers类代码示例

本文整理汇总了Java中com.yanzhenjie.nohttp.Headers的典型用法代码示例。如果您正苦于以下问题:Java Headers类的具体用法?Java Headers怎么用?Java Headers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Headers类属于com.yanzhenjie.nohttp包,在下文中一共展示了Headers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSucceed

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onSucceed(int what, Response<String> response) {
    if (what == NOHTTP_WHAT_TEST) {// 根据what判断是哪个请求的返回,这样就可以用一个OnResponseListener来接受多个请求的结果。
        int responseCode = response.getHeaders().getResponseCode();// 服务器响应码。

        String result = response.get();// 响应结果。

        mTvResult.setText(result);

        Object tag = response.getTag();// 拿到请求时设置的tag。

        // 响应头
        Headers headers = response.getHeaders();
        String headResult = getString(R.string.request_original_result);
        headResult = String.format(Locale.getDefault(), headResult, headers.getResponseCode(),
                response.getNetworkMillis());
        mTvResult.setText(headResult);
    }
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:20,代码来源:OriginalActivity.java

示例2: toString

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    Headers headers = getHeaders();
    if (headers != null) {
        Set<String> keys = headers.keySet();
        for (String key : keys) {
            List<String> values = headers.getValues(key);
            for (String value : values) {
                if (key != null) {
                    builder.append(key).append(": ");
                }
                builder.append(value).append("\n");
            }
        }
    }
    T result = get();
    if (result != null)
        builder.append(result.toString());
    return builder.toString();
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:22,代码来源:RestResponse.java

示例3: setRequestCacheHeader

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
/**
 * Perform the handle before, Handle the cache headers.
 *
 * @param request     the handle object.
 * @param cacheEntity cached entities.
 */
private void setRequestCacheHeader(BasicRequest<?> request, CacheEntity cacheEntity) {
    if (cacheEntity == null) {
        request.getHeaders().remove(Headers.HEAD_KEY_IF_NONE_MATCH);
        request.getHeaders().remove(Headers.HEAD_KEY_IF_MODIFIED_SINCE);
    } else {
        Headers headers = cacheEntity.getResponseHeaders();
        String eTag = headers.getETag();
        if (eTag != null)
            request.getHeaders().set(Headers.HEAD_KEY_IF_NONE_MATCH, eTag);

        long lastModified = headers.getLastModified();
        if (lastModified > 0)
            request.getHeaders().set(Headers.HEAD_KEY_IF_MODIFIED_SINCE, HeaderUtils.formatMillisToGMT(lastModified));
    }
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:22,代码来源:RequestHandler.java

示例4: parseResponse

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public Bitmap parseResponse(Headers responseHeaders, byte[] responseBody) throws Exception {
    synchronized (DECODE_LOCK) {
        Bitmap bitmap = null;
        if (responseBody != null) {
            try {
                bitmap = doResponse(responseBody);
            } catch (OutOfMemoryError e) {
                String errorMessage = String.format(Locale.US, "Caught OOM for %d byte image, url=%s",
                        responseBody.length, url());
                Logger.e(e, errorMessage);
            }
        }
        return bitmap;
    }
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:17,代码来源:ImageRequest.java

示例5: parseResponse

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public List<T> parseResponse(Headers responseHeaders, byte[] responseBody) {
    String response = StringRequest.parseResponseString(responseHeaders, responseBody);

    // 这里如果数据格式错误,或者解析失败,会在失败的回调方法中返回 ParseError 异常。
    return JSON.parseArray(response, clazz);
}
 
开发者ID:Qrilee,项目名称:MusicUU,代码行数:8,代码来源:JavaBeanRequest.java

示例6: onStart

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onStart(int what, boolean isResume, long beforeLength, Headers headers, long allCount) {
    int progress = AppConfig.getInstance().getInt(PROGRESS_KEY, 0);
    if (allCount != 0) {
        progress = (int) (beforeLength * 100 / allCount);
    }

    updateProgress(what, progress, 0);
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:10,代码来源:DownloadFileListActivity.java

示例7: onStart

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onStart(int what, boolean isResume, long beforeLength, Headers headers, long allCount) {
    int progress = AppConfig.getInstance().getInt(PROGRESS_KEY, 0);
    if (allCount != 0) {
        progress = (int) (beforeLength * 100 / allCount);
        mProgressBar.setProgress(progress);
    }
    updateProgress(progress, 0);

    mBtnStart.setText(R.string.download_status_pause);
    mBtnStart.setEnabled(true);
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:13,代码来源:DownloadSingleFileActivity.java

示例8: onSucceed

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onSucceed(int what, Response<String> response) {
    Headers headers = response.getHeaders();
    if (headers.getResponseCode() == 302 || headers.getResponseCode() == 301 || headers.getResponseCode() ==
            307) {
        String message = getString(R.string.request_redirect_location);
        message = String.format(Locale.getDefault(), message, headers.getLocation());
        showMessageDialog(R.string.request_succeed, message);
    } else if (headers.getResponseCode() == 200) {
        showMessageDialog(R.string.request_succeed, response.get());
    }
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:13,代码来源:RedirectActivity.java

示例9: parseResponse

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public T parseResponse(Headers responseHeaders, byte[] responseBody) throws Exception {
    String response = StringRequest.parseResponseString(responseHeaders, responseBody);

    // 这里如果数据格式错误,或者解析失败,会在失败的回调方法中返回 ParseError 异常。
    return JSON.parseObject(response, clazz);
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:8,代码来源:JavaBeanRequest.java

示例10: getConnectionRetry

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
private Connection getConnectionRetry(DownloadRequest downloadRequest) throws Exception {
    Connection connection = mHttpConnection.getConnection(downloadRequest);
    Exception exception = connection.exception();
    if (exception != null)
        throw exception;

    Headers responseHeaders = connection.responseHeaders();
    int responseCode = responseHeaders.getResponseCode();

    if (responseCode == 416) {
        downloadRequest.removeHeader("Range");
        return mHttpConnection.getConnection(downloadRequest);
    }
    return connection;
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:16,代码来源:Downloader.java

示例11: getRealFileName

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
private String getRealFileName(DownloadRequest request, Headers responseHeaders) throws IOException {
    String fileName = null;
    String contentDisposition = responseHeaders.getContentDisposition();
    if (!TextUtils.isEmpty(contentDisposition)) {
        fileName = HeaderUtils.parseHeadValue(contentDisposition, "filename", null);
        if (!TextUtils.isEmpty(fileName)) {
            try {
                fileName = URLDecoder.decode(fileName, request.getParamsEncoding());
            } catch (UnsupportedEncodingException e) {
                // Do nothing.
            }
            if (fileName.startsWith("\"") && fileName.endsWith("\"")) {
                fileName = fileName.substring(1, fileName.length() - 1);
            }
        }
    }

    // From url.
    if (TextUtils.isEmpty(fileName)) {
        String url = request.url();
        URI uri = URI.create(url);
        String path = uri.getPath();
        if (TextUtils.isEmpty(path)) {
            fileName = Integer.toString(url.hashCode());
        } else {
            String[] slash = path.split("/");
            fileName = slash[slash.length - 1];
        }
    }
    return fileName;
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:32,代码来源:Downloader.java

示例12: start

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
Poster start(boolean isResume, long beforeLength, Headers headers, long allCount) {
    this.command = -1;
    this.isResume = isResume;
    this.beforeLength = beforeLength;
    this.headers = headers;
    this.allCount = allCount;
    return this;
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:9,代码来源:Messenger.java

示例13: CacheEntity

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
/**
 * @param id              id.
 * @param key             key.
 * @param responseHeaders http response headers.
 * @param data            http response data.
 * @param localExpire     local expire time.
 */
public CacheEntity(long id, String key, Headers responseHeaders, byte[] data, long localExpire) {
    this.id = id;
    this.key = key;
    this.responseHeaders = responseHeaders;
    this.data = data;
    this.localExpire = localExpire;
}
 
开发者ID:yanzhenjie,项目名称:NoHttp,代码行数:15,代码来源:CacheEntity.java

示例14: Result

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
public Result(boolean isSucceed, Result result, Headers headers, String error) {
    this.isSucceed = isSucceed;
    this.result = result;
    this.headers = headers;
    this.error = error;
}
 
开发者ID:yanzhenjie,项目名称:LiveSourceCode,代码行数:7,代码来源:Result.java

示例15: getHeaders

import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
public Headers getHeaders() {
    return headers;
}
 
开发者ID:yanzhenjie,项目名称:LiveSourceCode,代码行数:4,代码来源:Result.java


注:本文中的com.yanzhenjie.nohttp.Headers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。