本文整理匯總了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;
}