@@ -126,7 +126,65 @@ class SVGAParser(private val context: Context) {
126
126
unzip(ByteArrayInputStream (bytes), cacheKey)
127
127
} catch (e: Exception ) { e.printStackTrace() }
128
128
}
129
+ try {
130
+ val cacheDir = File (context.cacheDir.absolutePath + " /" + cacheKey + " /" )
131
+ File (cacheDir, " movie.binary" ).takeIf { it.isFile }?.let { binaryFile ->
132
+ try {
133
+ FileInputStream (binaryFile).let {
134
+ val videoItem = SVGAVideoEntity (MovieEntity .ADAPTER .decode(it), cacheDir)
135
+ it.close()
136
+ return videoItem
137
+ }
138
+ } catch (e: Exception ) {
139
+ cacheDir.delete()
140
+ binaryFile.delete()
141
+ throw e
142
+ }
143
+ }
144
+ File (cacheDir, " movie.spec" ).takeIf { it.isFile }?.let { jsonFile ->
145
+ try {
146
+ FileInputStream (jsonFile).let { fileInputStream ->
147
+ val byteArrayOutputStream = ByteArrayOutputStream ()
148
+ val buffer = ByteArray (2048 )
149
+ while (true ) {
150
+ val size = fileInputStream.read(buffer, 0 , buffer.size)
151
+ if (size == - 1 ) {
152
+ break
153
+ }
154
+ byteArrayOutputStream.write(buffer, 0 , size)
155
+ }
156
+ byteArrayOutputStream.toString().let {
157
+ JSONObject (it).let {
158
+ fileInputStream.close()
159
+ return SVGAVideoEntity (it, cacheDir)
160
+ }
161
+ }
162
+ }
163
+ } catch (e: Exception ) {
164
+ cacheDir.delete()
165
+ jsonFile.delete()
166
+ throw e
167
+ }
168
+ }
169
+ } catch (e: Exception ) {
170
+ e.printStackTrace()
171
+ }
129
172
})
173
+ }
174
+ else {
175
+ try {
176
+ inflate(bytes)?.let {
177
+ return SVGAVideoEntity (MovieEntity .ADAPTER .decode(it), File (cacheKey))
178
+ }
179
+ } catch (e: Exception ) {
180
+ e.printStackTrace()
181
+ }
182
+ }
183
+ return null
184
+ }
185
+
186
+ private fun parseWithCacheKey (cacheKey : String ): SVGAVideoEntity ? {
187
+ synchronized(sharedLock, {
130
188
try {
131
189
val cacheDir = File (context.cacheDir.absolutePath + " /" + cacheKey + " /" )
132
190
File (cacheDir, " movie.binary" ).takeIf { it.isFile }?.let { binaryFile ->
@@ -170,63 +228,7 @@ class SVGAParser(private val context: Context) {
170
228
} catch (e: Exception ) {
171
229
e.printStackTrace()
172
230
}
173
- }
174
- else {
175
- try {
176
- inflate(bytes)?.let {
177
- return SVGAVideoEntity (MovieEntity .ADAPTER .decode(it), File (cacheKey))
178
- }
179
- } catch (e: Exception ) {
180
- e.printStackTrace()
181
- }
182
- }
183
- return null
184
- }
185
-
186
- private fun parseWithCacheKey (cacheKey : String ): SVGAVideoEntity ? {
187
- try {
188
- val cacheDir = File (context.cacheDir.absolutePath + " /" + cacheKey + " /" )
189
- File (cacheDir, " movie.binary" ).takeIf { it.isFile }?.let { binaryFile ->
190
- try {
191
- FileInputStream (binaryFile).let {
192
- val videoItem = SVGAVideoEntity (MovieEntity .ADAPTER .decode(it), cacheDir)
193
- it.close()
194
- return videoItem
195
- }
196
- } catch (e: Exception ) {
197
- cacheDir.delete()
198
- binaryFile.delete()
199
- throw e
200
- }
201
- }
202
- File (cacheDir, " movie.spec" ).takeIf { it.isFile }?.let { jsonFile ->
203
- try {
204
- FileInputStream (jsonFile).let { fileInputStream ->
205
- val byteArrayOutputStream = ByteArrayOutputStream ()
206
- val buffer = ByteArray (2048 )
207
- while (true ) {
208
- val size = fileInputStream.read(buffer, 0 , buffer.size)
209
- if (size == - 1 ) {
210
- break
211
- }
212
- byteArrayOutputStream.write(buffer, 0 , size)
213
- }
214
- byteArrayOutputStream.toString().let {
215
- JSONObject (it).let {
216
- fileInputStream.close()
217
- return SVGAVideoEntity (it, cacheDir)
218
- }
219
- }
220
- }
221
- } catch (e: Exception ) {
222
- cacheDir.delete()
223
- jsonFile.delete()
224
- throw e
225
- }
226
- }
227
- } catch (e: Exception ) {
228
- e.printStackTrace()
229
- }
231
+ })
230
232
return null
231
233
}
232
234
0 commit comments