Leanplum / Leanplum-Android-SDK

Leanplum's integrated solution delivers meaningful engagement across messaging and the in-app experience.
https://www.leanplum.com
Apache License 2.0
46 stars 40 forks source link

Fix VarCache.fileStreams #427

Closed hborisoff closed 4 years ago

hborisoff commented 4 years ago
What Where/Who
JIRA Issue SDK-152
People Involved @hborisoff

Background

There is a caching of InputStream instances in VarCache.fileStreams and a usage of them on several places. This produces a lot of bugs because when you use an InputStream you read it and close it, but InputStream cannot be read after it had been closed.

The stream cache cannot be easily removed because streams could come from several places - file system, bytes array, resource from ContentProvider, resource from the zipped res folder, etc.

Solution minimizes the changes to the codebase. Several changes are introduced:

  1. Replaced the InputStream with StreamProvider, which is not holding an InputStream instance but creating a new one when you call openStream().

  2. Separated VarCache.registerFile into two different registerFile methods to remove the isResource parameter.

  3. Some minor readability improvements.