diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-07-18 12:11:45 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-07-18 12:51:49 +0100 |
commit | 537a467dfd6392d70624805943ac65182ec881b4 (patch) | |
tree | cc2fc480bec283e99030c8eb7dbcf9090960f5a9 /platform/android/viewer/src/com | |
parent | cb62fbac8d7f4445aad87aa186ce80d5766ef22f (diff) | |
download | mupdf-537a467dfd6392d70624805943ac65182ec881b4.tar.xz |
Bug 696662: Android viewer: data from URI stream fix.
Apparently, if MuPDF is invoked on a content stream that
comes from a URI, then is.available() can report 0 bytes
(as there is no data buffered). Use a modified formulation
that reads as much data as possible from the stream into
a BufferedOutputStream and then makes a byte array from that.
Would be nicer if the core could actually read from the
stream directly, perhaps, but that can wait for the new JNI
based version.
Thanks to Marc K for identifying the problem and supplying
the patch.
Diffstat (limited to 'platform/android/viewer/src/com')
-rw-r--r-- | platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFActivity.java | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFActivity.java b/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFActivity.java index 08d32be9..3b8573f6 100644 --- a/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/platform/android/viewer/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -294,9 +294,14 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp String reason = null; try { InputStream is = getContentResolver().openInputStream(uri); - int len = is.available(); - buffer = new byte[len]; - is.read(buffer, 0, len); + int len; + ByteArrayOutputStream bufferStream = new ByteArrayOutputStream(); + byte[] data = new byte[16384]; + while ((len = is.read(data, 0, data.length)) != -1) { + bufferStream.write(data, 0, len); + } + bufferStream.flush(); + buffer = bufferStream.toByteArray(); is.close(); } catch (java.lang.OutOfMemoryError e) { |