本文整理汇总了Java中com.jakewharton.disklrucache.DiskLruCache.get方法的典型用法代码示例。如果您正苦于以下问题:Java DiskLruCache.get方法的具体用法?Java DiskLruCache.get怎么用?Java DiskLruCache.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jakewharton.disklrucache.DiskLruCache
的用法示例。
在下文中一共展示了DiskLruCache.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exist
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
static int exist(String name) {
DiskLruCache diskLruCache = getDiskLruCache();
if (diskLruCache == null) {
return -1;
}
try {
DiskLruCache.Snapshot snapshot = diskLruCache.get(name);
if (snapshot == null) {
return -1;
}
InputStream stream = snapshot.getInputStream(1);
boolean hasBitmap = readBoolean(stream);
return hasBitmap ? 1 : 0;
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
示例2: readFromCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
@Override
public DrawableSizeHolder readFromCache(String key, DiskLruCache cache) {
if (cache != null) {
try {
DiskLruCache.Snapshot snapshot = cache.get(key);
if (snapshot == null) {
return null;
}
InputStream inputStream = snapshot.getInputStream(0);
DrawableSizeHolder drawableSizeHolder = DrawableSizeHolder.read(inputStream, key);
inputStream.close();
return drawableSizeHolder;
} catch (IOException e) {
Debug.e(e);
}
}
return null;
}
示例3: save
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
void save() {
DiskLruCache diskLruCache = getDiskLruCache();
if (diskLruCache != null) {
try {
DiskLruCache.Snapshot snapshot = diskLruCache.get(name);
if (snapshot == null) {
DiskLruCache.Editor edit = diskLruCache.edit(name);
// write size
OutputStream sizeOutputStream = edit.newOutputStream(0);
sizeCacheHolder.save(sizeOutputStream);
// write bitmap
OutputStream bitmapOutputStream = edit.newOutputStream(1);
writeBoolean(bitmapOutputStream, bitmap != null);
if (bitmap != null) {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bitmapOutputStream);
}
bitmapOutputStream.flush();
bitmapOutputStream.close();
// write bitmap
edit.commit();
}
} catch (IOException e) {
Debug.e(e);
}
}
}
示例4: hasCacheInDisk
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
public static boolean hasCacheInDisk(DiskLruCache diskLruCache, String key) {
if (diskLruCache != null && !diskLruCache.isClosed() && !TextUtils.isEmpty(key)) {
try {
DiskLruCache.Snapshot snapshot = diskLruCache.get(key);
if (snapshot != null) {
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
return false;
}
示例5: hasCache
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
@Override
public boolean hasCache(String key, DiskLruCache cache) {
if (cache != null) {
try {
DiskLruCache.Snapshot snapshot = cache.get(key);
return snapshot != null;
} catch (IOException e) {
Debug.e(e);
}
}
return false;
}
示例6: read
import com.jakewharton.disklrucache.DiskLruCache; //导入方法依赖的package包/类
static BitmapWrapper read(String name, boolean readBitmap) {
DiskLruCache diskLruCache = getDiskLruCache();
if (diskLruCache != null) {
try {
DiskLruCache.Snapshot snapshot = diskLruCache.get(name);
if (snapshot == null) {
return null;
}
InputStream sizeInputStream = snapshot.getInputStream(0);
SizeCacheHolder sizeCacheHolder = SizeCacheHolder.read(sizeInputStream, name);
if (sizeCacheHolder == null) {
return null;
}
Bitmap bitmap = null;
if (readBitmap) {
InputStream bitmapInputStream = snapshot.getInputStream(1);
boolean hasBitmap = readBoolean(bitmapInputStream);
if (hasBitmap) {
bitmap = decodeBitmap(bitmapInputStream, null);
}
bitmapInputStream.close();
}
return new BitmapWrapper(name, bitmap, sizeCacheHolder);
} catch (IOException e) {
Debug.e(e);
}
}
return null;
}