Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
fix: Creating a cache file may cause a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
caiyuwei committed Nov 28, 2020
1 parent f25b11a commit e0dd50b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object SVGACache {
if (isInitialized()) return
context ?: return
cacheDir = "${context.cacheDir.absolutePath}/svga/"
File(cacheDir).takeIf { !it.exists() }?.mkdir()
File(cacheDir).takeIf { !it.exists() }?.mkdirs()
this.type = type
}

Expand Down
10 changes: 8 additions & 2 deletions library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.net.http.HttpResponseCache
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.opensource.svgaplayer.proto.MovieEntity
import com.opensource.svgaplayer.utils.log.LogUtils
import org.json.JSONObject
Expand Down Expand Up @@ -237,8 +238,13 @@ class SVGAParser(context: Context?) {
readAsBytes(inputStream)?.let { bytes ->
threadPoolExecutor.execute {
SVGACache.buildSvgaFile(cacheKey).let { cacheFile ->
cacheFile.takeIf { !it.exists() }?.createNewFile()
FileOutputStream(cacheFile).write(bytes)
try {
cacheFile.takeIf { !it.exists() }?.createNewFile()
FileOutputStream(cacheFile).write(bytes)
} catch (e: Exception) {
LogUtils.error(TAG, "create cache file fail.", e)
cacheFile.delete()
}
}
}
LogUtils.info(TAG, "Input.inflate start")
Expand Down

0 comments on commit e0dd50b

Please sign in to comment.