java.net.CacheResponse Java Examples
The following examples show how to use
java.net.CacheResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpResponseCache.java From cordova-android-chromeview with Apache License 2.0 | 6 votes |
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); } }
Example #2
Source File: HttpResponseCache.java From reader with MIT License | 6 votes |
@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); }
Example #3
Source File: HttpResponseCache.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: HttpResponseCache.java From L.TileLayer.Cordova with MIT License | 6 votes |
@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); }
Example #5
Source File: HttpResponseCache.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
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); } }
Example #6
Source File: HttpResponseCache.java From cordova-android-chromeview with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: HttpResponseCache.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 6 votes |
@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); }
Example #8
Source File: HttpResponseCache.java From wildfly-samples with MIT License | 6 votes |
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); } }
Example #9
Source File: HttpResponseCache.java From android-discourse with Apache License 2.0 | 6 votes |
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); } }
Example #10
Source File: HttpResponseCache.java From IoTgo_Android_App with MIT License | 6 votes |
@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); }
Example #11
Source File: HttpResponseCache.java From android-discourse with Apache License 2.0 | 6 votes |
@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); }
Example #12
Source File: HttpResponseCache.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
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); } }
Example #13
Source File: HttpResponseCache.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 6 votes |
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); } }
Example #14
Source File: HttpResponseCache.java From reader with MIT License | 6 votes |
@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); }
Example #15
Source File: HttpEngine.java From L.TileLayer.Cordova with MIT License | 5 votes |
/** * 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(); } }
Example #16
Source File: HttpEngine.java From android-discourse with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example #17
Source File: JnlpResponseCache.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
@Override public CacheResponse get (URI uri, String rqstMethod, Map<String, List<String>> rqstHeaders) throws IOException { return null; }
Example #18
Source File: HttpEngine.java From IoTgo_Android_App with MIT License | 5 votes |
/** * 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(); } }
Example #19
Source File: HttpEngine.java From cordova-android-chromeview with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example #20
Source File: HttpEngine.java From reader with MIT License | 5 votes |
/** * 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(); } }
Example #21
Source File: HttpResponseCache.java From reader with MIT License | 4 votes |
@Override public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException { return HttpResponseCache.this.get(uri, requestMethod, requestHeaders); }
Example #22
Source File: OkResponseCacheAdapter.java From bluemix-parking-meter with MIT License | 4 votes |
@Override public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException { return responseCache.get(uri, requestMethod, requestHeaders); }
Example #23
Source File: OkResponseCache.java From reader with MIT License | 4 votes |
CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException;
Example #24
Source File: HttpEngine.java From cordova-amazon-fireos with Apache License 2.0 | 4 votes |
public final CacheResponse getCacheResponse() { return cacheResponse; }
Example #25
Source File: HttpResponseCache.java From cordova-android-chromeview with Apache License 2.0 | 4 votes |
@Override public void update( CacheResponse conditionalCacheHit, HttpURLConnection connection) throws IOException { HttpResponseCache.this.update(conditionalCacheHit, connection); }
Example #26
Source File: HttpResponseCache.java From reader with MIT License | 4 votes |
@Override public void update( CacheResponse conditionalCacheHit, HttpURLConnection connection) throws IOException { HttpResponseCache.this.update(conditionalCacheHit, connection); }
Example #27
Source File: TestCache.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public synchronized CacheResponse get(final URI uri, String rqstMethod, Map requestHeaders) throws IOException { System.out.println("get: " + uri); Thread.currentThread().dumpStack(); return null; }
Example #28
Source File: HttpResponseCache.java From android-discourse with Apache License 2.0 | 4 votes |
@Override public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException { return HttpResponseCache.this.get(uri, requestMethod, requestHeaders); }
Example #29
Source File: HttpResponseCache.java From wildfly-samples with MIT License | 4 votes |
@Override public void update( CacheResponse conditionalCacheHit, HttpURLConnection connection) throws IOException { HttpResponseCache.this.update(conditionalCacheHit, connection); }
Example #30
Source File: OkResponseCacheAdapter.java From phonegapbootcampsite with MIT License | 4 votes |
@Override public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException { return responseCache.get(uri, requestMethod, requestHeaders); }