Beispiel #1
0
 @Override
 public Response get(Request request) throws IOException {
   CacheResponse javaResponse = getJavaCachedResponse(request);
   if (javaResponse == null) {
     return null;
   }
   return JavaApiConverter.createOkResponseForCacheGet(request, javaResponse);
 }
Beispiel #2
0
  @Override
  public CacheRequest put(Response response) throws IOException {
    URI uri = response.request().url().uri();
    HttpURLConnection connection = JavaApiConverter.createJavaUrlConnectionForCachePut(response);
    final java.net.CacheRequest request = delegate.put(uri, connection);
    if (request == null) {
      return null;
    }
    return new CacheRequest() {
      @Override
      public Sink body() throws IOException {
        OutputStream body = request.getBody();
        return body != null ? Okio.sink(body) : null;
      }

      @Override
      public void abort() {
        request.abort();
      }
    };
  }
Beispiel #3
0
 /**
  * Returns the {@link CacheResponse} from the delegate by converting the OkHttp {@link Request}
  * into the arguments required by the {@link ResponseCache}.
  */
 private CacheResponse getJavaCachedResponse(Request request) throws IOException {
   Map<String, List<String>> headers = JavaApiConverter.extractJavaHeaders(request);
   return delegate.get(request.url().uri(), request.method(), headers);
 }