本文整理汇总了Java中com.jakewharton.DiskLruCache类的典型用法代码示例。如果您正苦于以下问题:Java DiskLruCache类的具体用法?Java DiskLruCache怎么用?Java DiskLruCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiskLruCache类属于com.jakewharton包,在下文中一共展示了DiskLruCache类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: writeToDiskCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
protected boolean writeToDiskCache(URL url, Bitmap bitmap){
boolean isOk = false;
if(diskCache != null){
String cacheKey = MD5.encode(url.toString());
try {
DiskLruCache.Editor editor = diskCache.edit(cacheKey);
if(editor != null){
OutputStream out = editor.newOutputStream(0);
bitmap.compress(CompressFormat.PNG, 95, out);
out.close();
editor.commit();
//Log.d(Constants.TAG_EMOP, "write to disk key:" + cacheKey + ", url:" + url.toString());
isOk = true;
editor = null;
}
} catch (IOException e) {
isOk = false;
Log.d(Constants.TAG_EMOP, "write disk lru cache error:" + e.toString(), e);
}
}else {
Log.w(Constants.TAG_EMOP, "read disk lru cache is null");
}
return isOk;
}
开发者ID:emop,项目名称:EmopAndroid,代码行数:25,代码来源:ImageCache.java
示例2: initHttpDiskCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
private void initHttpDiskCache() {
if (!mHttpCacheDir.exists()) {
mHttpCacheDir.mkdirs();
}
synchronized (mHttpDiskCacheLock) {
long usableSpace = ImageCache.getUsableSpace(mHttpCacheDir);
try {
if (usableSpace > HTTP_CACHE_SIZE) {
usableSpace = HTTP_CACHE_SIZE;
}
mHttpDiskCache = DiskLruCache.open(mHttpCacheDir, 1, 1, usableSpace);
if (BuildConfig.DEBUG) {
Log.d(TAG, "HTTP cache initialized");
}
} catch (IOException e) {
mHttpDiskCache = null;
}
mHttpDiskCacheStarting = false;
mHttpDiskCacheLock.notifyAll();
}
}
开发者ID:generify,项目名称:image-cache-android,代码行数:22,代码来源:ImageFetcher.java
示例3: readFromDiskCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
protected Bitmap readFromDiskCache(URL url){
Bitmap bm = null;
if(diskCache != null){
//diskCache.flush()
String cacheKey = MD5.encode(url.toString());
try {
DiskLruCache.Snapshot snapshot = diskCache.get(cacheKey);
if(snapshot != null){
InputStream in = snapshot.getInputStream(0);
bm = BitmapFactory.decodeStream(in);
in.close();
snapshot.close();
snapshot = null;
//Log.d(Constants.TAG_EMOP, "read from disk key:" + cacheKey + ", url:" + url.toString());
}
} catch (IOException e) {
Log.d(Constants.TAG_EMOP, "read disk lru cache error:" + e.toString(), e);
}
}else {
Log.w(Constants.TAG_EMOP, "read disk lru cache is null");
}
return bm;
}
开发者ID:emop,项目名称:EmopAndroid,代码行数:25,代码来源:ImageCache.java
示例4: putBitmap
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
@Override
public void putBitmap(String key, Bitmap data) {
DiskLruCache.Editor editor = null;
try {
editor = mDiskCache.edit(key);
if (editor == null) {
return;
}
if (writeBitmapToFile(data, editor)) {
mDiskCache.flush();
editor.commit();
} else {
editor.abort();
}
} catch (IOException e) {
try {
if (editor != null) {
editor.abort();
}
} catch (IOException ignored) {
}
}
}
开发者ID:Richie97,项目名称:Quiver,代码行数:27,代码来源:DiskLruImageCache.java
示例5: containsKey
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
public boolean containsKey(String key) {
boolean contained = false;
DiskLruCache.Snapshot snapshot = null;
try {
snapshot = mDiskCache.get(key);
contained = snapshot != null;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (snapshot != null) {
snapshot.close();
}
}
return contained;
}
开发者ID:Richie97,项目名称:Quiver,代码行数:19,代码来源:DiskLruImageCache.java
示例6: writeBitmapToFile
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
private boolean writeBitmapToFile( Bitmap bitmap, DiskLruCache.Editor editor ) throws IOException, FileNotFoundException {
OutputStream out = null;
try {
out = new BufferedOutputStream( editor.newOutputStream(0), IO_BUFFER_SIZE );
return bitmap.compress(BITMAP_COMPRESS_FORMAT, BITMAP_COMPRESS_QUALITY, out);
} finally {
if ( out != null ) {
out.close();
}
}
}
开发者ID:Openredu,项目名称:mobile,代码行数:12,代码来源:CacheManager.java
示例7: getImage
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
public BufferedInputStream getImage(String key) throws IOException{
DiskLruCache.Snapshot snapshot;
if(imageCache == null)
return null;
snapshot = imageCache.get(Integer.toString(key.hashCode()));
if (snapshot == null)
return null;
return new BufferedInputStream(snapshot.getInputStream(0));
}
开发者ID:helderm,项目名称:songseeker,代码行数:13,代码来源:FileCache.java
示例8: ImageCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
public ImageCache(File root, final int cacheSize){
this.cacheRoot = root;
memCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
int size = bitmap.getHeight() * bitmap.getWidth() * 4;
return size;
}
};
lockCache = new LruCache<String, Lock>(200) {
@Override
protected int sizeOf(String key, Lock obj) {
return 1;
}
};
if(diskCache == null && root != null){
try {
Log.d(Constants.TAG_EMOP, "create LRU cache in:" + root.getAbsolutePath());
diskCache = DiskLruCache.open(root, 1, 1, 1024 * 1024 * 64);
} catch (IOException e) {
Log.w(Constants.TAG_EMOP, "open disk cache error:" + e.toString(), e);
}
}
}
开发者ID:emop,项目名称:EmopAndroid,代码行数:28,代码来源:ImageCache.java
示例9: cleanUpDiskCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
public void cleanUpDiskCache(){
if(diskCache != null){
File f = diskCache.getDirectory();
try {
memCache.evictAll();
diskCache.delete();
diskCache = DiskLruCache.open(f, 1, 1, 1024 * 1024 * 64);
} catch (IOException e) {
Log.w(Constants.TAG_EMOP, "open disk cache error:" + e.toString(), e);
}
}
}
开发者ID:emop,项目名称:EmopAndroid,代码行数:13,代码来源:ImageCache.java
示例10: initDiskCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
/**
* Initializes the disk cache. Note that this includes disk access so this should not be
* executed on the main/UI thread. By default an ImageCache does not initialize the disk
* cache when it is created, instead you should call initDiskCache() to initialize it on a
* background thread.
*/
public void initDiskCache() {
// Set up disk cache
synchronized (mDiskCacheLock) {
if (mDiskLruCache == null || mDiskLruCache.isClosed()) {
File diskCacheDir = mCacheParams.diskCacheDir;
if (mCacheParams.diskCacheEnabled && diskCacheDir != null) {
if (!diskCacheDir.exists()) {
diskCacheDir.mkdirs();
}
if (getUsableSpace(diskCacheDir) > mCacheParams.diskCacheSize) {
try {
mDiskLruCache = DiskLruCache.open(
diskCacheDir, 1, 1, mCacheParams.diskCacheSize);
if (BuildConfig.DEBUG) {
Log.d(TAG, "Disk cache initialized");
}
} catch (final IOException e) {
mCacheParams.diskCacheDir = null;
Log.e(TAG, "initDiskCache - " + e);
}
}
}
}
mDiskCacheStarting = false;
mDiskCacheLock.notifyAll();
}
}
开发者ID:generify,项目名称:image-cache-android,代码行数:34,代码来源:ImageCache.java
示例11: DiskLruImageCache
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
public DiskLruImageCache(Context context, String uniqueName, int diskCacheSize,
Bitmap.CompressFormat compressFormat, int quality) {
try {
final File diskCacheDir = getDiskCacheDir(context, uniqueName);
mDiskCache = DiskLruCache.open(diskCacheDir, APP_VERSION, VALUE_COUNT, diskCacheSize);
mCompressFormat = compressFormat;
mCompressQuality = quality;
} catch (IOException e) {
e.printStackTrace();
}
}
开发者ID:Richie97,项目名称:Quiver,代码行数:12,代码来源:DiskLruImageCache.java
示例12: writeBitmapToFile
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
private boolean writeBitmapToFile(Bitmap bitmap, DiskLruCache.Editor editor)
throws IOException, FileNotFoundException {
OutputStream out = null;
try {
out = new BufferedOutputStream(editor.newOutputStream(0), IO_BUFFER_SIZE);
return bitmap.compress(mCompressFormat, mCompressQuality, out);
} finally {
if (out != null) {
out.close();
}
}
}
开发者ID:Richie97,项目名称:Quiver,代码行数:13,代码来源:DiskLruImageCache.java
示例13: getBitmap
import com.jakewharton.DiskLruCache; //导入依赖的package包/类
@Override
public Bitmap getBitmap(String key) {
Bitmap bitmap = null;
DiskLruCache.Snapshot snapshot = null;
try {
snapshot = mDiskCache.get(key);
if (snapshot == null) {
return null;
}
final InputStream in = snapshot.getInputStream(0);
if (in != null) {
final BufferedInputStream buffIn =
new BufferedInputStream(in, IO_BUFFER_SIZE);
bitmap = BitmapFactory.decodeStream(buffIn);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (snapshot != null) {
snapshot.close();
}
}
return bitmap;
}
开发者ID:Richie97,项目名称:Quiver,代码行数:29,代码来源:DiskLruImageCache.java
注:本文中的com.jakewharton.DiskLruCache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论