app/src/main/java/me/zhanghai/android/douya/util/DiskCache.java
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*
* Copyright (c) 2015 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
* All Rights Reserved.
*/
package me.zhanghai.android.douya.util;
import android.util.LruCache;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import com.jakewharton.disklrucache.DiskLruCache;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Type;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class DiskCache {
private DiskLruCache mCache;
private SafeKeyGenerator mSafeKeyGenerator = new SafeKeyGenerator();
private DiskCache(DiskLruCache cache) {
mCache = cache;
}
public static DiskCache openOrThrow(File directory, int version, long maxSize)
throws IOException {
return new DiskCache(DiskLruCache.open(directory, version, 1, maxSize));
}
public static DiskCache open(File directory, int version, long maxSize) {
try {
return openOrThrow(directory, version, maxSize);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
private DiskLruCache.Snapshot getOrThrow(String key) throws IOException, NullPointerException {
DiskLruCache.Snapshot snapshot = mCache.get(mSafeKeyGenerator.getSafeKey(key));
if (snapshot == null) {
throw new NullPointerException("DiskLruCache.get() returned null");
}
return snapshot;
}
public InputStream getInputStreamOrThrow(String key) throws IOException, NullPointerException {
return getOrThrow(key).getInputStream(0);
}
后面还有 175 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
