diff --git a/app/src/main/java/com/fuying/sn/core/data/local/cache/CacheHelper.java b/app/src/main/java/com/fuying/sn/core/data/local/cache/CacheHelper.java index 8a8a0c8..d695c64 100644 --- a/app/src/main/java/com/fuying/sn/core/data/local/cache/CacheHelper.java +++ b/app/src/main/java/com/fuying/sn/core/data/local/cache/CacheHelper.java @@ -69,7 +69,7 @@ public class CacheHelper { dir + " is not a directory or does not exists. "); } - int appVersion = context == null ? DEFAULT_APP_VERSION : Utils.getAppVersion(context); + int appVersion = context == null ? DEFAULT_APP_VERSION : DiskCacheUtils.getAppVersion(context); try { return DiskLruCache.open( @@ -87,7 +87,7 @@ public class CacheHelper { try { return DiskLruCache.open( getDiskCacheDir(context, dirName), - Utils.getAppVersion(context), + DiskCacheUtils.getAppVersion(context), DEFAULT_APP_VERSION, maxCount); } catch (IOException e) { @@ -340,7 +340,7 @@ public class CacheHelper { // ============== bitmap 数据 读写 ============= // ======================================= public void put(String key, Bitmap bitmap) { - put(key, Utils.bitmap2Bytes(bitmap)); + put(key, DiskCacheUtils.bitmap2Bytes(bitmap)); } public Bitmap getAsBitmap(String key) { @@ -348,14 +348,14 @@ public class CacheHelper { if (bytes == null) { return null; } - return Utils.bytes2Bitmap(bytes); + return DiskCacheUtils.bytes2Bitmap(bytes); } // ======================================= // ============= drawable 数据 读写 ============= // ======================================= public void put(String key, Drawable value) { - put(key, Utils.drawable2Bitmap(value)); + put(key, DiskCacheUtils.drawable2Bitmap(value)); } public Drawable getAsDrawable(String key) { @@ -363,7 +363,7 @@ public class CacheHelper { if (bytes == null) { return null; } - return Utils.bitmap2Drawable(Utils.bytes2Bitmap(bytes)); + return DiskCacheUtils.bitmap2Drawable(DiskCacheUtils.bytes2Bitmap(bytes)); } // ======================================= @@ -371,7 +371,7 @@ public class CacheHelper { // ======================================= public boolean remove(String key) { try { - String hashKey = Utils.hashKeyForDisk(key); + String hashKey = DiskCacheUtils.hashKeyForDisk(key); return mDiskLruCache.remove(hashKey); } catch (IOException e) { e.printStackTrace(); @@ -418,7 +418,7 @@ public class CacheHelper { //basic editor public DiskLruCache.Editor editor(String key) { try { - String hashKey = Utils.hashKeyForDisk(key); + String hashKey = DiskCacheUtils.hashKeyForDisk(key); //wirte DIRTY DiskLruCache.Editor edit = mDiskLruCache.edit(hashKey); //edit maybe null :the entry is editing @@ -438,7 +438,7 @@ public class CacheHelper { //basic get public InputStream get(String key) { try { - DiskLruCache.Snapshot snapshot = mDiskLruCache.get(Utils.hashKeyForDisk(key)); + DiskLruCache.Snapshot snapshot = mDiskLruCache.get(DiskCacheUtils.hashKeyForDisk(key)); if (snapshot == null) //not find entry , or entry.readable = false { Log.e(TAG, "not find entry , or entry.readable = false"); diff --git a/app/src/main/java/com/fuying/sn/core/data/local/cache/Utils.java b/app/src/main/java/com/fuying/sn/core/data/local/cache/DiskCacheUtils.java similarity index 96% rename from app/src/main/java/com/fuying/sn/core/data/local/cache/Utils.java rename to app/src/main/java/com/fuying/sn/core/data/local/cache/DiskCacheUtils.java index d8ddd97..3dbbe1f 100644 --- a/app/src/main/java/com/fuying/sn/core/data/local/cache/Utils.java +++ b/app/src/main/java/com/fuying/sn/core/data/local/cache/DiskCacheUtils.java @@ -14,7 +14,10 @@ import java.io.ByteArrayOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -public class Utils { +/** + * 磁盘缓存底层工具:版本号、缓存键哈希与 Bitmap/Drawable 互转。 + */ +public class DiskCacheUtils { public static int getAppVersion(Context context) { try { PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);