Example #1
0
 private Response response(DiskLruCache.Snapshot snapshot) throws IOException {
   String contentType = responseHeaders.get("Content-Type");
   Request cacheRequest =
       new Request.Builder()
           .url(url)
           .method(requestMethod, requestBody)
           .headers(varyHeaders)
           .build();
   BufferedSource source = Okio.buffer(snapshot.getSource(RESPONSE_BODY));
   byte[] bodyContent = source.readByteArray();
   MediaType mediaType = contentType == null ? null : MediaType.parse(contentType);
   return new Response.Builder()
       .request(cacheRequest)
       .protocol(protocol)
       .code(code)
       .message(message)
       .headers(responseHeaders)
       .body(new OkHttpUtil.ReusableResponseBody(mediaType, bodyContent))
       .handshake(handshake)
       .build();
 }
Example #2
0
 public static Response deserializeResponse(DiskLruCache.Snapshot snapshot) throws IOException {
   Source source = snapshot.getSource(RESPONSE_METADATA);
   return new Entry(source).response(snapshot);
 }