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


Java CacheResponse.getBody方法代码示例

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


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

示例1: get

import java.net.CacheResponse; //导入方法依赖的package包/类
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) throws IOException {
  final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
  if (response instanceof SecureCacheResponse) {
    return new CacheResponse() {
      @Override public InputStream getBody() throws IOException {
        return response.getBody();
      }

      @Override public Map<String, List<String>> getHeaders() throws IOException {
        return response.getHeaders();
      }
    };
  }
  return response;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:ResponseCacheTest.java

示例2: fetchFromHTTPUrlConnectionCache

import java.net.CacheResponse; //导入方法依赖的package包/类
/**
 * Fetches an entry value from the HttpResponseCache cache
 * @param connection connection from which we need the cache
 * @param uri uri to use to get the cache entry
 * @return cache entry value as String
 */
private String fetchFromHTTPUrlConnectionCache(HttpURLConnection connection, URI uri) {

    try {
        HttpResponseCache responseCache = HttpResponseCache.getInstalled();
        if(responseCache != null){
            CacheResponse cacheResponse = responseCache.get(uri, "GET", connection.getRequestProperties());
            Scanner scanner = new Scanner(cacheResponse.getBody(), "UTF-8");
            StringBuilder sb = new StringBuilder();
            while (scanner.hasNextLine()){
                sb.append(scanner.nextLine());
            }

            return sb.toString();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;

}
 
开发者ID:nico-gonzalez,项目名称:volley-it,代码行数:28,代码来源:MainActivity.java

示例3: initResponseSource

import java.net.CacheResponse; //导入方法依赖的package包/类
/**
 * Initialize the source for this response. It may be corrected later if the
 * request headers forbids network use.
 */
private void initResponseSource() throws IOException {
  responseSource = ResponseSource.NETWORK;
  if (!policy.getUseCaches()) return;

  OkResponseCache responseCache = client.getOkResponseCache();
  if (responseCache == null) return;

  CacheResponse candidate = responseCache.get(
      uri, method, requestHeaders.getHeaders().toMultimap(false));
  if (candidate == null) return;

  Map<String, List<String>> responseHeadersMap = candidate.getHeaders();
  cachedResponseBody = candidate.getBody();
  if (!acceptCacheResponseType(candidate)
      || responseHeadersMap == null
      || cachedResponseBody == null) {
    Util.closeQuietly(cachedResponseBody);
    return;
  }

  RawHeaders rawResponseHeaders = RawHeaders.fromMultimap(responseHeadersMap, true);
  cachedResponseHeaders = new ResponseHeaders(uri, rawResponseHeaders);
  long now = System.currentTimeMillis();
  this.responseSource = cachedResponseHeaders.chooseResponseSource(now, requestHeaders);
  if (responseSource == ResponseSource.CACHE) {
    this.cacheResponse = candidate;
    setResponse(cachedResponseHeaders, cachedResponseBody);
  } else if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
    this.cacheResponse = candidate;
  } else if (responseSource == ResponseSource.NETWORK) {
    Util.closeQuietly(cachedResponseBody);
  } else {
    throw new AssertionError();
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:40,代码来源:HttpEngine.java

示例4: initResponseSource

import java.net.CacheResponse; //导入方法依赖的package包/类
/**
 * Initialize the source for this response. It may be corrected later if the
 * request headers forbids network use.
 */
private void initResponseSource() throws IOException {
    responseSource = ResponseSource.NETWORK;
    if (!policy.getUseCaches())
        return;

    OkResponseCache responseCache = client.getOkResponseCache();
    if (responseCache == null)
        return;

    CacheResponse candidate = responseCache.get(uri, method, requestHeaders.getHeaders().toMultimap(false));
    if (candidate == null)
        return;

    Map<String, List<String>> responseHeadersMap = candidate.getHeaders();
    cachedResponseBody = candidate.getBody();
    if (!acceptCacheResponseType(candidate) || responseHeadersMap == null || cachedResponseBody == null) {
        Util.closeQuietly(cachedResponseBody);
        return;
    }

    RawHeaders rawResponseHeaders = RawHeaders.fromMultimap(responseHeadersMap, true);
    cachedResponseHeaders = new ResponseHeaders(uri, rawResponseHeaders);
    long now = System.currentTimeMillis();
    this.responseSource = cachedResponseHeaders.chooseResponseSource(now, requestHeaders);
    if (responseSource == ResponseSource.CACHE) {
        this.cacheResponse = candidate;
        setResponse(cachedResponseHeaders, cachedResponseBody);
    } else if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
        this.cacheResponse = candidate;
    } else if (responseSource == ResponseSource.NETWORK) {
        Util.closeQuietly(cachedResponseBody);
    } else {
        throw new AssertionError();
    }
}
 
开发者ID:goodev,项目名称:android-discourse,代码行数:40,代码来源:HttpEngine.java


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