Android CacheResponse: get file path?

76 views Asked by At

Is there a way to retrieve the file path of an Android CacheResponse? Sure, one can get an InputStream, but in cases where some API (e.g. NDK code) expects a file path that does not help. Sure one can use this stream to produce another file, but that's more time and space.

2

There are 2 answers

2
Jess Holle On

Ok, so pondering this a bit further (and poking at the code), I have to assume that response headers, etc, are in the same file -- not just the response body. If so, then there would clearly be no file path one could provide that was simply the response body. Confirmation would be helpful -- as would pointers to alternative HTTP caching libraries that would help here.

0
Erik Gustavsson On

I've run into this myself.

On Android (tested on Jellybean), the cache file path is the lowercase MD5-sum of the URI followed by

.1

So for the URL Android CacheResponse: get file path? the following files exists in the cache-directory.

  • bf9b8f9a33062f084a70cba99dc79afe.0 - contains the headers of the HTTP response
  • bf9b8f9a33062f084a70cba99dc79afe.1 - contains the body of the HTTP response