@@ -2,7 +2,9 @@ package com.opensource.svgaplayer
2
2
3
3
import android.app.Activity
4
4
import android.content.Context
5
+ import android.net.http.HttpResponseCache
5
6
import android.os.Handler
7
+ import android.util.Log
6
8
import com.opensource.svgaplayer.proto.MovieEntity
7
9
8
10
import org.json.JSONObject
@@ -31,9 +33,15 @@ class SVGAParser(private val context: Context) {
31
33
32
34
open class FileDownloader {
33
35
36
+ var noCache = false
37
+
34
38
open fun resume (url : URL , complete : (inputStream: InputStream ) -> Unit , failure : (e: Exception ) -> Unit ) {
35
39
Thread ({
36
40
try {
41
+ if (HttpResponseCache .getInstalled() == null && ! noCache) {
42
+ Log .e(" SVGAParser" , " SVGAParser can not handle cache before install HttpResponseCache. see https://github.com/yyued/SVGAPlayer-Android#cache" )
43
+ Log .e(" SVGAParser" , " 在配置 HttpResponseCache 前 SVGAParser 无法缓存. 查看 https://github.com/yyued/SVGAPlayer-Android#cache " )
44
+ }
37
45
(url.openConnection() as ? HttpURLConnection )?.let {
38
46
it.connectTimeout = 20 * 1000
39
47
it.requestMethod = " GET"
@@ -226,20 +234,16 @@ class SVGAParser(private val context: Context) {
226
234
val messageDigest = MessageDigest .getInstance(" MD5" )
227
235
messageDigest.update(str.toByteArray(charset(" UTF-8" )))
228
236
val digest = messageDigest.digest()
229
- val sb = StringBuffer ()
237
+ var sb = " "
230
238
for (b in digest) {
231
- sb.append( String .format(" %02x" , b) )
239
+ sb + = String .format(" %02x" , b)
232
240
}
233
- return sb.toString()
241
+ return sb
234
242
}
235
243
236
- private fun cacheKey (url : URL ): String {
237
- return cacheKey(url.toString())
238
- }
244
+ private fun cacheKey (url : URL ): String = cacheKey(url.toString())
239
245
240
- private fun cacheDir (cacheKey : String ): File {
241
- return File (context.cacheDir.absolutePath + " /" + cacheKey + " /" )
242
- }
246
+ private fun cacheDir (cacheKey : String ): File = File (context.cacheDir.absolutePath + " /" + cacheKey + " /" )
243
247
244
248
private fun readAsBytes (inputStream : InputStream ): ByteArray {
245
249
val byteArrayOutputStream = ByteArrayOutputStream ()
0 commit comments