[6.5.0] tmp
This commit is contained in:
@@ -2,6 +2,8 @@ package com.mogo.eagle.core.utilcode.mogo.storage.lrucache;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.util.Md5Util;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -66,7 +68,7 @@ public class DiskCacheManager {
|
||||
* @throws IOException
|
||||
*/
|
||||
private DiskLruCache.Editor edit( String key) throws IOException {
|
||||
key = SecretUtil.getMD5Result(key); //存取的 key
|
||||
key = Md5Util.getMD5Result(key); //存取的 key
|
||||
if (mDiskLruCache != null) {
|
||||
mEditor = mDiskLruCache.edit(key);
|
||||
}
|
||||
@@ -349,7 +351,7 @@ public class DiskCacheManager {
|
||||
* @return InputStream
|
||||
*/
|
||||
private InputStream getCacheInputStream( String key) {
|
||||
key = SecretUtil.getMD5Result(key);
|
||||
key = Md5Util.getMD5Result(key);
|
||||
InputStream in;
|
||||
DiskLruCache.Snapshot snapshot = snapshot(key);
|
||||
if (snapshot == null) {
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.mogo.storage.lrucache;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class SecretUtil {
|
||||
|
||||
public static String getMD5Result( String value) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(value.getBytes("UTF-8"));
|
||||
byte[] result = md.digest();
|
||||
return getString(result);
|
||||
} catch ( NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
} catch ( UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getString( byte[] result) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : result) {
|
||||
int i = b & 0xff;
|
||||
if (i <= 0xf) {
|
||||
sb.append(0);
|
||||
}
|
||||
sb.append( Integer.toHexString(i));
|
||||
}
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.mogo.eagle.core.utilcode.util
|
||||
|
||||
import java.io.*
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.nio.channels.FileChannel.MapMode
|
||||
import java.security.*
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.util.Locale
|
||||
|
||||
class Md5Util {
|
||||
|
||||
@@ -39,5 +43,34 @@ class Md5Util {
|
||||
}
|
||||
return stringbuffer?.toString()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMD5Result(value: String): String {
|
||||
try {
|
||||
val md = MessageDigest.getInstance("MD5")
|
||||
md.update(value.toByteArray(charset("UTF-8")))
|
||||
val result = md.digest()
|
||||
return getString(result)
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
e.printStackTrace()
|
||||
return ""
|
||||
} catch (e: UnsupportedEncodingException) {
|
||||
e.printStackTrace()
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun getString(result: ByteArray): String {
|
||||
val sb = StringBuilder()
|
||||
for (b in result) {
|
||||
val i = b.toInt() and 0xff
|
||||
if (i <= 0xf) {
|
||||
sb.append(0)
|
||||
}
|
||||
sb.append(Integer.toHexString(i))
|
||||
}
|
||||
return sb.toString().lowercase(Locale.getDefault())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user