/** * Returns an editor for the entry named {@code key}, or null if another * edit is in progress. */ public Editor edit(String key) throws IOException { return edit(key, ANY_SEQUENCE_NUMBER); }
editor = mDiskCache.edit( key ); if ( editor == null ) { return;
DiskLruCache.Editor editor = mDiskCache.edit(key); os = editor.newOutputStream(0); bitmap.compress(compressFormat, compressQuality, os);
DiskLruCache.Editor editor = mDiskCache.edit(key); IoUtils.copy(tmpFile, editor.newOutputStream(0)); editor.commit();
@Override public Bitmap put(String key, Bitmap data) { if (contains(key)) { return data; } DiskLruCache.Editor editor = null; try { editor = mDiskCache.edit(key); if (editor != null) { if (writeBitmapToCache(data, editor)) { mDiskCache.flush(); editor.commit(); } else { editor.abort(); } } } catch (IOException e) { try { if (editor != null) { editor.abort(); } } catch (IOException ignored) { // } } return data; }
private Editor getEditor(LoaderRequest request) throws IOException { String key = hashKeyForDisk(request); Editor editor = cache.edit(key); if (editor == null) { throw new IOException("File is already being edited"); } return editor; }
/** * 获取缓存 editor * * @param key 缓存的key * @return editor * @throws IOException */ private DiskLruCache.Editor edit(String key) throws IOException { key = SecretUtil.getMD5Result(key); //存取的 key if (mDiskLruCache != null) { mEditor = mDiskLruCache.edit(key); } return mEditor; }
DiskLruCache.Editor cacheItem = diskCache.edit(urlToDiskCacheKey(url.toString())); if (cacheItem == null) { Log.e("KDE/Mpris/AlbumArtCache",
@Override public <T> void addInCache(Response<T> response, byte[] rawResponse) { String cacheKey = urlToKey(response.raw().request().url().url()); memoryCache.put(cacheKey, rawResponse); try { DiskLruCache.Editor editor = diskCache.edit(urlToKey(response.raw().request().url().url())); editor.set(0, new String(rawResponse, Charset.defaultCharset())); editor.commit(); Log.e("SmartCall", "c缓存成功"); }catch(IOException exc){ Log.e("SmartCall", "", exc); } }
@Override public <T> void addInCache(Response<T> response, byte[] rawResponse) { String cacheKey = urlToKey(response.raw().request().url().url()); memoryCache.put(cacheKey, rawResponse); try { DiskLruCache.Editor editor = diskCache.edit(urlToKey(response.raw().request().url().url())); editor.set(0, new String(rawResponse, Charset.defaultCharset())); editor.commit(); }catch(IOException exc){ Log.e("SmartCall", "", exc); } }
@Override public <T> void addInCache(Response<T> response, byte[] rawResponse) { String cacheKey = urlToKey(response.raw().request().url().url()); memoryCache.put(cacheKey, rawResponse); try { DiskLruCache.Editor editor = diskCache.edit(urlToKey(response.raw().request().url().url())); editor.set(0, new String(rawResponse, Charset.defaultCharset())); editor.commit(); }catch(IOException exc){ Log.e("SmartCall", "", exc); } }
private void putToDiskQuietly(String key, V newValue) { if (mDiskCache == null) { return; } Editor editor = null; OutputStream out = null; try { editor = mDiskCache.edit(key); if (editor != null) { out = editor.newOutputStream(INDEX_VALUE); mConverter.toStream(newValue, out); editor.commit(); } } catch (IOException e) { System.out .println("Unable to put entry to disk cache. key: " + key); } finally { IOUtils.closeQuietly(out); quietlyAbortUnlessCommitted(editor); } }
public CacheableBitmapDrawable putInDiskCache(final String url, final CacheableBitmapDrawable drawable, Bitmap.CompressFormat compressFormat, int compressQuality) { if (null != mDiskCache) { checkNotOnMainThread(); final String key = transformUrlForDiskCacheKey(url); final ReentrantLock lock = getLockForDiskCacheEdit(key); lock.lock(); OutputStream os = null; try { DiskLruCache.Editor editor = mDiskCache.edit(key); os = editor.newOutputStream(0); drawable.getBitmap().compress(compressFormat, compressQuality, os); os.flush(); editor.commit(); } catch (IOException e) { Log.e(Constants.LOG_TAG, "Error while writing to disk cache", e); } finally { IoUtils.closeStream(os); lock.unlock(); scheduleDiskCacheFlush(); } } return drawable; }
@Override protected <T> boolean doSave(String key, T value) { if (mDiskLruCache == null) { return false; } try { DiskLruCache.Editor edit = mDiskLruCache.edit(key); if (edit == null) { return false; } OutputStream sink = edit.newOutputStream(0); if (sink != null) { boolean result = mDiskConverter.writer(sink, value); Utils.close(sink); edit.commit(); return result; } edit.abort(); } catch (IOException e) { e.printStackTrace(); } return false; }
@Override protected <T> T doLoad(Type type, String key) { if (mDiskLruCache == null) { return null; } try { DiskLruCache.Editor edit = mDiskLruCache.edit(key); if (edit == null) { return null; } InputStream source = edit.newInputStream(0); T value; if (source != null) { value = mDiskConverter.load(source,type); Utils.close(source); edit.commit(); return value; } edit.abort(); } catch (IOException e) { e.printStackTrace(); } return null; }
@Override public void put(String key, File value, CacheLoadFinishListener listener) { if (diskLruCache == null || value == null || TextUtils.isEmpty(key)) { return; } DiskLruCache.Editor editor = null; try { String cacheKey = cacheKeyProvider.buildCacheKey(key); editor = diskLruCache.edit(cacheKey); if (editor != null) { OutputStream os = editor.newOutputStream(0); if (writeCache(value, os) && listener != null) { listener.onFinished(); } editor.commit(); } diskLruCache.flush(); } catch (IOException e) { try { if (editor != null) { editor.abort(); } } catch (IOException e1) { e1.printStackTrace(); } } }
private void putDataToDiskLruCache(Image image) { try { /* 第一步:获取将要缓存的图片的对应唯一 key 值 */ String key = DiskCacheUtil.getMD5String(image.getUrl()); /* 第二步:获取 DiskLruCache 的 Editor */ DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (null != editor) { /* 第三步:从 Editor 中获取 OutputStream */ OutputStream outputStream = editor.newOutputStream(0); /* 第四步:下载网络图片且保存至 DiskLruCache 图片中 */ boolean isSuccessful = download(image.getUrl(), outputStream); if (isSuccessful) { editor.commit(); } else { editor.abort(); } mDiskLruCache.flush(); } } catch (IOException e) { e.printStackTrace(); } }
/** * 下载图片放入本地缓存 * @param urlString 下载图片的链接 * @throws IOException */ public void downloadImageToDiskCache(String urlString) throws IOException { if(mDiskLruCache == null){ return ; } String key =MD5Utils.hashKeyFromUrl(urlString); DiskLruCache.Editor editor =mDiskLruCache.edit(key); if(editor != null){ //打开本地缓存的输入流 OutputStream outputStream =editor.newOutputStream(DISK_CACHE_INDEX); //将从网络下载并写入输出流中 if(NetRequest.downloadUrlToStream(urlString,outputStream)){ //提交数据,并是释放连接 editor.commit(); }else{ //释放连接 editor.abort(); } mDiskLruCache.flush(); } }
try { dualCacheLock.lockDiskEntryWrite(key); DiskLruCache.Editor editor = diskLruCache.edit(key); if (ramSerializer == diskSerializer) {
try { dualCacheLock.lockDiskEntryWrite(key); DiskLruCache.Editor editor = diskLruCache.edit(key); if (ramSerializer == diskSerializer) {