@Override public InputStream getInputStream() { try { DiskLruCache.Snapshot snapshot = mDiskCache.get(mKey); if (snapshot != null) { return snapshot.getInputStream(0); } } catch (IOException e) { Log.e(Constants.LOG_TAG, "Could open disk cache for url: " + mKey, e); } return null; } }
@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; }
public Object get(String key) { DiskLruCache.Snapshot snapshot; try { snapshot = mDiskCache.get(key); ObjectInputStream in = new ObjectInputStream(snapshot.getInputStream(0)); return (Object) in.readObject(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } }
final byte[] data = readStreamAsByteArray(snapshot.getInputStream(INDEX_DATA)); final int height = readStreamAsInt(snapshot.getInputStream(INDEX_HEIGHT)); final int width = readStreamAsInt(snapshot.getInputStream(INDEX_WIDTH)); if (data != null) { if (BuildConfig.DEBUG)Log.d(TAG, "Cache hit for tile " + key);
Log.i(getTag(), "Snapshot found sending"); if (snapshot != null) return (FileInputStream) snapshot.getInputStream(DISK_CACHE_INDEX); } catch (IOException e) { e.printStackTrace();
DiskLruCache.Snapshot item = diskCache.get(urlToDiskCacheKey(albumUrl)); if (item != null) { Bitmap result = BitmapFactory.decodeStream(item.getInputStream(0)); item.close(); MemoryCacheItem memItem = new MemoryCacheItem();
snapshot = mDiskCache.get(key); if (snapshot != null) { in = snapshot.getInputStream(INDEX_VALUE); byte[] bytes = IOUtils.toByteArray(in); value = mConverter.from(bytes);
length = Long.parseLong(storedLength); inputStream = snapshot.getInputStream(1); return new CacheEntry(length, new ByteArrayInputStream(IOUtils.toByteArray(inputStream))); } catch (Exception e) {
/** * 从本地缓存加载bitmap * @param url * @param reqWidth * @param reqHeight * @return * @throws IOException */ public Bitmap loadBitmapFromDiskCache(String url,int reqWidth,int reqHeight) throws IOException { if(mDiskLruCache ==null){ return null; } Bitmap bitmap=null; String key = MD5Utils.hashKeyFromUrl(url); DiskLruCache.Snapshot snapshot =mDiskLruCache.get(key); if(snapshot!=null){ FileInputStream fileInputStream =(FileInputStream)snapshot.getInputStream(DISK_CACHE_INDEX); if(reqWidth<=0||reqHeight<=0){ //不压缩图片 bitmap = BitmapFactory.decodeFileDescriptor(fileInputStream.getFD()); }else{ //按需求分辨率压缩图片 bitmap =BitmapUtils.getSmallBitmap(fileInputStream.getFD(),reqWidth,reqHeight); } } return bitmap; }
private Bitmap getDataFromDiskLruCache(String url) { FileDescriptor fileDescriptor = null; FileInputStream fileInputStream = null; DiskLruCache.Snapshot snapShot = null; try { /* 生成图片对应的 MD5 值 */ final String key = DiskCacheUtil.getMD5String(url); snapShot = mDiskLruCache.get(key); if (null != snapShot) { fileInputStream = (FileInputStream) snapShot.getInputStream(0); fileDescriptor = fileInputStream.getFD(); } /* 将缓存数据解析成 Bitmap 对象 */ Bitmap bitmap = null; if (null != fileDescriptor) { bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor); } return bitmap; } catch (IOException e) { e.printStackTrace(); } finally { CloseUtil.closeQuietly(fileInputStream); } return null; }
@Override public InputStream getInput() throws IOException { if (snapshot == null) { snapshot = cache.get(key); if (snapshot == null) { throw new IOException("Snapshot not available"); } } // Wrap input stream so we can close the snapshot return new FilterInputStream(snapshot.getInputStream(INPUT_IMAGE)) { @Override public void close() throws IOException { super.close(); snapshot.close(); snapshot = null; } }; } }
@Override public InputStream get(String key) { if (diskLruCache == null || TextUtils.isEmpty(key)) { return null; } try { String cacheKey = cacheKeyProvider.buildCacheKey(key); DiskLruCache.Snapshot snapshot = diskLruCache.get(cacheKey); if (snapshot != null) { return snapshot.getInputStream(0); } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * 获取 缓存数据的 InputStream * * @param key cache'key * @return InputStream */ private InputStream getCacheInputStream(String key) { key = SecretUtil.getMD5Result(key); InputStream in; DiskLruCache.Snapshot snapshot = snapshot(key); if (snapshot == null) { return null; } in = snapshot.getInputStream(0); return in; }
@Override public InputStream getInputStream() { try { DiskLruCache.Snapshot snapshot = mDiskCache.get(mKey); if (snapshot != null) { return snapshot.getInputStream(0); } } catch (IOException e) { Log.e(Constants.LOG_TAG, "Could open disk cache for url: " + mKey, e); } return null; } }
private Metadata readMetadata(Snapshot snapshot) throws IOException { // Use a small buffer as the metadata itself is small InputStream is = new BufferedInputStream(snapshot.getInputStream(INPUT_METADATA), 1024); try { return Metadata.from(is); } finally { is.close(); } }
/** Returns the string value for {@code index}. */ public String getString(int index) throws IOException { return inputStreamToString(getInputStream(index)); }