Close JsonReader after parsing
Other streams are closed so this makes it consistent with that.
Fixes
@@ -238,12 +238,21 @@ public class LottieCompositionFactory {
*/
@WorkerThread
public static LottieResult<LottieComposition> fromJsonReaderSync(JsonReader reader, @Nullable String cacheKey) {
+ return fromJsonReaderSyncInternal(reader, cacheKey, true);
+ }
+
+ private static LottieResult<LottieComposition> fromJsonReaderSyncInternal(
+ JsonReader reader, @Nullable String cacheKey, boolean close) {
try {
LottieComposition composition = LottieCompositionParser.parse(reader);
LottieCompositionCache.getInstance().put(cacheKey, composition);
return new LottieResult<>(composition);
} catch (Exception e) {
return new LottieResult<>(e);
+ } finally {
+ if (close) {
+ closeQuietly(reader);
+ }
}
}
@@ -280,7 +289,8 @@ public class LottieCompositionFactory {
if (entry.getName().contains("__MACOSX")) {
inputStream.closeEntry();
} else if (entry.getName().contains(".json")) {
- composition = LottieCompositionFactory.fromJsonInputStreamSync(inputStream, cacheKey, false).getValue();
+ JsonReader reader = new JsonReader(new InputStreamReader(inputStream));
+ composition = LottieCompositionFactory.fromJsonReaderSyncInternal(reader, null, false).getValue();
} else if (entry.getName().contains(".png")) {
String[] splitName = entry.getName().split("/");
String name = splitName[splitName.length - 1];
