Skip to content

Commit

Permalink
fix(android): calculate correct stream size
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Oct 30, 2019
1 parent 02096c2 commit ed9286a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.util.KrollAssetHelper;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiFileHelper2;

import android.content.Context;
import javax.crypto.CipherInputStream;

public class TiResourceFile extends TiBaseFile
{
Expand Down Expand Up @@ -193,6 +192,18 @@ public long size()
InputStream is = null;
try {
is = getInputStream();

// CipherInputStream.available() always returns 0
// Iterate through stream to obtain true size.
if (is instanceof CipherInputStream) {
long size = 0;
long skipped = 0;
while ((skipped = is.skip(4096)) != -1) {
size += skipped;
}
return size;
}

return is.available();
} catch (IOException e) {
Log.w(TAG, "Error while trying to determine file size: " + e.getMessage(), e);
Expand Down

0 comments on commit ed9286a

Please sign in to comment.