• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DiskLruCache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Direction类代码示例发布时间:2022-05-22
下一篇:
Java RowResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap