diff options
author | Damjan Jovanovic <damjan@apache.org> | 2023-02-27 20:19:39 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-02-28 11:12:06 +0000 |
commit | f4d147ef956de834a7402bea88a1aec296c38ef7 (patch) | |
tree | c4cea05c601c41637973584e95f40f27fd862aab /ridljar | |
parent | 4f743219e85e61f622a8dadc028c144010eecd4d (diff) |
InputStreamToXInputStreamAdapter.readBytes() should read...
until the buffer is full, or the file ends. It shouldn't care about
available().
(cherry-picked from f04910427d25ede98b84b90df7cc5a12d1adc695)
Change-Id: I4ad17c614ba336ff21883248715861f6af1fbc2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147934
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'ridljar')
-rw-r--r-- | ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java index d547b1e7ce17..dd634e771370 100644 --- a/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java +++ b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java @@ -79,29 +79,24 @@ public final class InputStreamToXInputStreamAdapter implements XInputStream { { try { long bytesRead; + int totalBytesRead = 0; if (b[0] == null || b[0].length < len) { b[0] = new byte[len]; } - if (len >iIn.available()) { - bytesRead = iIn.read(b[0], 0, iIn.available()); - } - else{ - bytesRead = iIn.read(b[0], 0, len); - } // Casting bytesRead to an int is okay, since the user can // only pass in an integer length to read, so the bytesRead // must <= len. - if (bytesRead < b[0].length) { - int outSize = bytesRead > 0 ? (int)bytesRead : 0; - byte[] out = new byte[outSize]; - System.arraycopy(b[0], 0, out, 0, outSize); - b[0] = out; + while ((len > 0) && ((bytesRead = iIn.read(b[0], totalBytesRead, len)) > 0)) { + totalBytesRead += (int)bytesRead; + len -= (int)bytesRead; } - if (bytesRead <= 0) { - return 0; + if (totalBytesRead < b[0].length) { + byte[] out = new byte[totalBytesRead]; + System.arraycopy(b[0], 0, out, 0, totalBytesRead); + b[0] = out; } - return ((int)bytesRead); + return totalBytesRead; } catch (IOException e) { throw new com.sun.star.io.IOException("reader error", e); } |