public InputStream get(String key) throws IOException { return get(key, null); }
boolean hasValue(FileLruCache cache, String key) { InputStream stream = null; try { stream = cache.get(key); } catch (IOException e) { // Fail test and print Exception assertNull(e); } return stream != null; }
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; }
FileLruCache cache = getCache(); boolean redirectExists = false; while ((stream = cache.get(uriString, REDIRECT_CONTENT_TAG)) != null) { redirectExists = true;
void checkValue(FileLruCache cache, String key, byte[] expected) { try { InputStream stream = cache.get(key); assertNotNull(stream); checkInputStream(expected, stream); stream.close(); } catch (IOException e) { // Fail test and print Exception assertNull(e); } }
/** * NOTE: This MUST be called ONLY via the CreateLikeActionControllerWorkItem class to ensure * that it happens on the right thread, at the right time. */ private static LikeActionController deserializeFromDiskSynchronously(String objectId) { LikeActionController controller = null; InputStream inputStream = null; try { String cacheKey = getCacheKeyForObjectId(objectId); inputStream = controllerDiskCache.get(cacheKey); if (inputStream != null) { String controllerJsonString = Utility.readStreamToString(inputStream); if (!Utility.isNullOrEmpty(controllerJsonString)) { controller = deserializeFromJson(controllerJsonString); } } } catch (IOException e) { Log.e(TAG, "Unable to deserialize controller from disk", e); controller = null; } finally { if (inputStream != null) { Utility.closeQuietly(inputStream); } } return controller; }
private Bitmap readImage(String uri, boolean expectedFromCache) { Bitmap bmp = null; InputStream istream = null; try { Uri url = Uri.parse(uri); // Check if the cache contains value for this url boolean isInCache = (ImageResponseCache.getCache(safeGetContext()).get(url.toString()) != null); assertTrue(isInCache == expectedFromCache); // Read the image istream = ImageResponseCache.getCachedImageStream(url, safeGetContext()); if (istream == null) { HttpURLConnection connection = (HttpURLConnection) (new URL(uri)).openConnection(); istream = ImageResponseCache.interceptAndCacheImageStream( safeGetContext(), connection); } assertTrue(istream != null); bmp = BitmapFactory.decodeStream(istream); assertTrue(bmp != null); } catch (Exception e) { assertNull(e); } finally { Utility.closeQuietly(istream); } return bmp; }
public InputStream get(String key) throws IOException { return get(key, null); }
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; }
FileLruCache cache = getCache(context); boolean redirectExists = false; while ((stream = cache.get(uriString, REDIRECT_CONTENT_TAG)) != null) { redirectExists = true;
stream = cache.get(cacheKey); if (stream != null) { return createResponsesFromStream(stream, null, requests, true);