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


Java Response.header方法代码示例

本文整理汇总了Java中com.squareup.okhttp.Response.header方法的典型用法代码示例。如果您正苦于以下问题:Java Response.header方法的具体用法?Java Response.header怎么用?Java Response.header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.Response的用法示例。


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

示例1: prepareDownloadFile

import com.squareup.okhttp.Response; //导入方法依赖的package包/类
/**
 * Prepare file for download
 *
 * @param response An instance of the Response object
 * @throws IOException If fail to prepare file for download
 * @return Prepared file for the download
 */
public File prepareDownloadFile(Response response) throws IOException {
    String filename = null;
    String contentDisposition = response.header("Content-Disposition");
    if (contentDisposition != null && !"".equals(contentDisposition)) {
        // Get filename from the Content-Disposition header.
        Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
        Matcher matcher = pattern.matcher(contentDisposition);
        if (matcher.find()) {
            filename = sanitizeFilename(matcher.group(1));
        }
    }

    String prefix = null;
    String suffix = null;
    if (filename == null) {
        prefix = "download-";
        suffix = "";
    } else {
        int pos = filename.lastIndexOf(".");
        if (pos == -1) {
            prefix = filename + "-";
        } else {
            prefix = filename.substring(0, pos) + "-";
            suffix = filename.substring(pos);
        }
        // File.createTempFile requires the prefix to be at least three characters long
        if (prefix.length() < 3)
            prefix = "download-";
    }

    if (tempFolderPath == null)
        return File.createTempFile(prefix, suffix);
    else
        return File.createTempFile(prefix, suffix, new File(tempFolderPath));
}
 
开发者ID:ina-foss,项目名称:afp-api-client,代码行数:43,代码来源:ApiClient.java

示例2: toWebResource

import com.squareup.okhttp.Response; //导入方法依赖的package包/类
protected WebResourceResponse toWebResource(Response response) throws IOException {
    if (response == null || !response.isSuccessful()) {
        return null;
    }

    String mimeType = response.header("Content-Type");
    String charset = response.header("charset");
    return new WebResourceResponse(mimeType, charset, response.body().byteStream());
}
 
开发者ID:fivef,项目名称:add_to_evernote_note,代码行数:10,代码来源:ViewHtmlActivity.java

示例3: isCacheable

import com.squareup.okhttp.Response; //导入方法依赖的package包/类
public static boolean isCacheable(Response response, Request request) {
    switch (response.code()) {
        case 200:
        case 203:
        case 204:
        case 300:
        case SampleTinkerReport.KEY_LOADED_MISMATCH_LIB /*301*/:
        case 308:
        case SampleTinkerReport.KEY_LOADED_SUCC_COST_OTHER /*404*/:
        case 405:
        case 410:
        case 414:
        case 501:
            break;
        case SampleTinkerReport.KEY_LOADED_MISMATCH_RESOURCE /*302*/:
        case 307:
            if (response.header("Expires") == null && response.cacheControl().maxAgeSeconds()
                    == -1 && !response.cacheControl().isPublic() && !response.cacheControl()
                    .isPrivate()) {
                return false;
            }
        default:
            return false;
    }
    return (response.cacheControl().noStore() || request.cacheControl().noStore()) ? false :
            true;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:CacheStrategy.java

示例4: onRet

import com.squareup.okhttp.Response; //导入方法依赖的package包/类
private void onRet(Response response, String ip, long duration, CompletionHandler complete) {
    int code = response.code();
    String reqId = response.header("X-Reqid");
    reqId = reqId == null ? null : reqId.trim();
    byte[] body = null;
    String error = null;
    try {
        body = response.body().bytes();
    } catch (IOException e) {
        error = e.getMessage();
    }
    JSONObject json = null;
    if (!ctype(response).equals("application/json") || body == null) {
        String str = new String(body);
    } else {
        try {
            json = buildJsonResp(body);
            if (response.code() != 200) {
                error = json.optString("error", new String(body, Constants.UTF_8));
            }
        } catch (Exception e2) {
            if (response.code() < 300) {
                error = e2.getMessage();
            }
        }
    }
    URL u = response.request().url();
    final ResponseInfo info = new ResponseInfo(code, reqId, response.header("X-Log"), via
            (response), u.getHost(), u.getPath(), ip, u.getPort(), (double) duration, 0, error);
    final CompletionHandler completionHandler = complete;
    final JSONObject jSONObject = json;
    AsyncRun.run(new Runnable() {
        public void run() {
            completionHandler.complete(info, jSONObject);
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:Client.java

示例5: onOpen

import com.squareup.okhttp.Response; //导入方法依赖的package包/类
@Override
public void onOpen(final WebSocket webSocket, Response response) {
    String protocol = response.header(STREAM_PROTOCOL_HEADER, "missing");
    listener.open(protocol, webSocket);
}
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:6,代码来源:WebSockets.java


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