From 537a467dfd6392d70624805943ac65182ec881b4 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 18 Jul 2016 12:11:45 +0100 Subject: 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. --- .../viewer/src/com/artifex/mupdfdemo/MuPDFActivity.java | 11 ++++++++--- 1 file 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) { -- cgit v1.2.3