@Override public Bitmap get(String key) { DiskLruCache.Snapshot snapshot = null; try { snapshot = mDiskCache.get(key); if (snapshot == null) { return null; } InputStream inputStream = snapshot.getInputStream(0); if (inputStream != null) { BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, IO_BUFFER_SIZE); return BitmapFactory.decodeStream(bufferedInputStream); } } catch (IOException e) { // no op } finally { if (snapshot != null) { snapshot.close(); } } return null; }
@Override public void close() throws IOException { super.close(); snapshot.close(); snapshot = null; } };
if (item != null) { Bitmap result = BitmapFactory.decodeStream(item.getInputStream(0)); item.close(); MemoryCacheItem memItem = new MemoryCacheItem(); if (result != null) {
@Override protected void loadInBackground(LoaderWork.Manager manager, LoaderRequest request) throws IOException { Snapshot snapshot = getSnapshot(request); if (snapshot != null) { try { if (Logger.VERBOSE) Log.v(TAG, "Loaded " + request + " from disk"); Metadata metadata = readMetadata(snapshot); DiskInputSupplier input = new DiskInputSupplier(request, snapshot); manager.deliverStream(input, metadata); long expires = metadata.getExpires(); if (expires != Metadata.NEVER_EXPIRES && System.currentTimeMillis() > expires) { // Cache has expired if (Logger.VERBOSE) Log.v(TAG, request + " has expired, updating"); manager.next(request.withMetadata(metadata), new NextListener(request, manager)); } } finally { snapshot.close(); } } else { // We need to add the next loader manager.next(request, new NextListener(request, manager)); } }
public boolean isCacheExists(String key) { DiskLruCache.Snapshot snapshot = null; try { snapshot = diskLruCache.get(cacheKeyProvider.buildCacheKey(key)); } catch (IOException e) { e.printStackTrace(); } if (snapshot == null) { return false; } snapshot.close(); return true; }
private boolean contains(String key) { boolean contained = false; DiskLruCache.Snapshot snapshot = null; try { snapshot = mDiskCache.get(key); contained = snapshot != null; } catch (IOException e) { // no op } finally { if (snapshot != null) { snapshot.close(); } } return contained; }