类java.net.CacheResponse源码实例Demo

下面列出了怎么用java.net.CacheResponse的API类实例代码及写法,或者点击链接到github查看源代码。

private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
源代码3 项目: L.TileLayer.Cordova   文件: HttpResponseCache.java
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
源代码4 项目: IoTgo_Android_App   文件: HttpResponseCache.java
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
源代码7 项目: android-discourse   文件: HttpResponseCache.java
@Override
public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) {
    String key = uriToKey(uri);
    DiskLruCache.Snapshot snapshot;
    Entry entry;
    try {
        snapshot = cache.get(key);
        if (snapshot == null) {
            return null;
        }
        entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
    } catch (IOException e) {
        // Give up because the cache cannot be read.
        return null;
    }

    if (!entry.matches(uri, requestMethod, requestHeaders)) {
        snapshot.close();
        return null;
    }

    return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot) : new EntryCacheResponse(entry, snapshot);
}
 
源代码8 项目: android-discourse   文件: HttpResponseCache.java
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection) throws IOException {
    HttpEngine httpEngine = getHttpEngine(httpConnection);
    URI uri = httpEngine.getUri();
    ResponseHeaders response = httpEngine.getResponseHeaders();
    RawHeaders varyHeaders = httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
    Entry entry = new Entry(uri, varyHeaders, httpConnection);
    DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse) ? ((EntryCacheResponse) conditionalCacheHit).snapshot : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
    DiskLruCache.Editor editor = null;
    try {
        editor = snapshot.edit(); // returns null if snapshot is not current
        if (editor != null) {
            entry.writeTo(editor);
            editor.commit();
        }
    } catch (IOException e) {
        abortQuietly(editor);
    }
}
 
源代码9 项目: cordova-amazon-fireos   文件: HttpResponseCache.java
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
源代码11 项目: reader   文件: HttpResponseCache.java
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
源代码13 项目: wildfly-samples   文件: HttpResponseCache.java
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
源代码14 项目: reader   文件: HttpResponseCache.java
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) {
  String key = uriToKey(uri);
  DiskLruCache.Snapshot snapshot;
  Entry entry;
  try {
    snapshot = cache.get(key);
    if (snapshot == null) {
      return null;
    }
    entry = new Entry(snapshot.getInputStream(ENTRY_METADATA));
  } catch (IOException e) {
    // Give up because the cache cannot be read.
    return null;
  }

  if (!entry.matches(uri, requestMethod, requestHeaders)) {
    snapshot.close();
    return null;
  }

  return entry.isHttps() ? new EntrySecureCacheResponse(entry, snapshot)
      : new EntryCacheResponse(entry, snapshot);
}
 
源代码15 项目: cordova-android-chromeview   文件: HttpEngine.java
/**
 * 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() || policy.responseCache == null) {
    return;
  }

  CacheResponse candidate =
      policy.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();
  }
}
 
源代码16 项目: L.TileLayer.Cordova   文件: HttpEngine.java
/**
 * 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();
  }
}
 
源代码17 项目: IoTgo_Android_App   文件: HttpEngine.java
/**
 * 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();
  }
}
 
源代码18 项目: android-discourse   文件: HttpEngine.java
/**
 * 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();
    }
}
 
源代码19 项目: libreveris   文件: JnlpResponseCache.java
@Override
public CacheResponse get (URI                       uri,
                          String                    rqstMethod,
                          Map<String, List<String>> rqstHeaders)
    throws IOException
{
    return null;
}
 
源代码20 项目: reader   文件: HttpEngine.java
/**
 * 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();
  }
}
 
源代码21 项目: android_9.0.0_r45   文件: HttpResponseCache.java
@Override public CacheResponse get(URI uri, String requestMethod,
        Map<String, List<String>> requestHeaders) throws IOException {
    return delegate.get(uri, requestMethod, requestHeaders);
}
 
源代码22 项目: dragonwell8_jdk   文件: TestCache.java
public synchronized CacheResponse get(final URI uri, String rqstMethod,
        Map requestHeaders) throws IOException {
    System.out.println("get: " + uri);
    Thread.currentThread().dumpStack();
    return null;
}
 
源代码23 项目: crosswalk-cordova-android   文件: HttpsEngine.java
@Override protected boolean acceptCacheResponseType(CacheResponse cacheResponse) {
  return cacheResponse instanceof SecureCacheResponse;
}
 
@Override public void update(
    CacheResponse conditionalCacheHit, HttpURLConnection connection) throws IOException {
  HttpResponseCache.this.update(conditionalCacheHit, connection);
}
 
源代码25 项目: openjdk-jdk8u   文件: TestCache.java
public synchronized CacheResponse get(final URI uri, String rqstMethod,
        Map requestHeaders) throws IOException {
    System.out.println("get: " + uri);
    Thread.currentThread().dumpStack();
    return null;
}
 
源代码26 项目: openjdk-jdk9   文件: TestCache.java
public synchronized CacheResponse get(final URI uri, String rqstMethod,
        Map requestHeaders) throws IOException {
    System.out.println("get: " + uri);
    Thread.currentThread().dumpStack();
    return null;
}
 
@Override public void update(CacheResponse conditionalCacheHit, HttpURLConnection connection)
    throws IOException {
}
 
@Override public void update(
    CacheResponse conditionalCacheHit, HttpURLConnection connection) throws IOException {
  HttpResponseCache.this.update(conditionalCacheHit, connection);
}
 
源代码29 项目: openjdk-8   文件: TestCache.java
public synchronized CacheResponse get(final URI uri, String rqstMethod,
        Map requestHeaders) throws IOException {
    System.out.println("get: " + uri);
    Thread.currentThread().dumpStack();
    return null;
}
 
源代码30 项目: jdk8u_jdk   文件: TestCache.java
public synchronized CacheResponse get(final URI uri, String rqstMethod,
        Map requestHeaders) throws IOException {
    System.out.println("get: " + uri);
    Thread.currentThread().dumpStack();
    return null;
}
 
 类所在包
 类方法
 同包方法