Closed sumio closed 7 years ago
@sumio good call on the use of available()
. However, I think it's much better to use Okio
to handle file reads as it's already a dependency. Something like the code below should work. I haven't read Okio
source code yet but I believe it solves that issue. If not, feel free to ignore this.
String json = null;
BufferedSource source = null;
try {
final InputStream is = context.getAssets().open("json/" + jsonFileName);
source = Okio.buffer(Okio.source(is));
json = source.readUtf8();
} catch (IOException e) {
Timber.tag(TAG).e(e, "assets/json/%s: read failed", jsonFileName);
} finally {
try {
if (source != null) {
source.close();
}
} catch (IOException e) {
Timber.tag(TAG).e(e, "assets/json/%s: read failed", jsonFileName);
}
}
return json;
:eyes:
@eyedol Thanks for your nice suggestion! I'll rewrite it by using Okio in this night.
Rewriting is done! commons-io dependecy is removed.
It seems that circleCI is failed in ContributorsLocalDataSourceTest > updateAllAsyncAsInsert
which is unrelated to this PR...
(and all tests are passed in my local environment)
@sumio Sorry, CircleCI is not stable now 🙇
@konifar Thanks for your reply. OK. I won't mind the result.
@sumio Sorry for late review 🙇 LGTM! Thanks for contribution! 💯 @eyedol Thanks for great suggestion! I appreciate you!
Hope CI success 🙏
👏
Issue
ResourceResolver.loadJSONFromAsset()
has the following code:The above code may read only partial content of the file because
is.available()
may return less than the length of the file.Overview (Required)
Links
N/A
Screenshot
N/A