static InputStream getCachedImageStream(Uri uri, Context context) { InputStream imageStream = null; if (uri != null) { if (isCDNURL(uri)) { try { FileLruCache cache = getCache(context); imageStream = cache.get(uri.toString()); } catch (IOException e) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString()); } } } return imageStream; }
static InputStream interceptAndCacheImageStream( Context context, HttpURLConnection connection ) throws IOException { InputStream stream = null; if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { Uri uri = Uri.parse(connection.getURL().toString()); stream = connection.getInputStream(); // Default stream in case caching fails try { if (isCDNURL(uri)) { FileLruCache cache = getCache(context); // Wrap stream with a caching stream stream = cache.interceptAndPut( uri.toString(), new BufferedHttpInputStream(stream, connection)); } } catch (IOException e) { // Caching is best effort } } return stream; }
static InputStream getCachedImageStream(URI url, Context context) { InputStream imageStream = null; if (url != null) { if (isCDNURL(url)) { try { FileLruCache cache = getCache(context); imageStream = cache.get(url.toString()); } catch (IOException e) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString()); } } } return imageStream; }
static InputStream interceptAndCacheImageStream(Context context, HttpURLConnection connection) throws IOException { InputStream stream = null; if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { URL url = connection.getURL(); stream = connection.getInputStream(); // Default stream in case caching fails try { if (isCDNURL(url.toURI())) { FileLruCache cache = getCache(context); // Wrap stream with a caching stream stream = cache.interceptAndPut( url.toString(), new BufferedHttpInputStream(stream, connection)); } } catch (IOException e) { // Caching is best effort } catch (URISyntaxException e) { // Caching is best effort } } return stream; }