You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ms...@apache.org on 2022/10/31 09:34:52 UTC
[openoffice] branch AOO41X updated: InputStreamToXInputStreamAdapter.readBytes() should read until the buffer is full, or the file ends. It shouldn't care about available().
This is an automated email from the ASF dual-hosted git repository.
mseidel pushed a commit to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/AOO41X by this push:
new 239988383a InputStreamToXInputStreamAdapter.readBytes() should read until the buffer is full, or the file ends. It shouldn't care about available().
239988383a is described below
commit 239988383ad44f763e210d38864f46a27e0a9873
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sun Oct 16 18:25:35 2022 +0200
InputStreamToXInputStreamAdapter.readBytes() should read until the buffer is full,
or the file ends. It shouldn't care about available().
Patch by: me
(cherry picked from commit f04910427d25ede98b84b90df7cc5a12d1adc695)
---
.../adapter/InputStreamToXInputStreamAdapter.java | 23 +++++++++-------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
index c68c8be276..fd9c58cd73 100644
--- a/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
+++ b/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
@@ -81,29 +81,24 @@ public class InputStreamToXInputStreamAdapter implements XInputStream {
int count = 0;
try {
long bytesRead=0;
+ 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);
+ while ((len > 0) && ((bytesRead = iIn.read(b[0], totalBytesRead, len)) > 0)) {
+ totalBytesRead += (int)bytesRead;
+ len -= (int)bytesRead;
+ }
+ if (totalBytesRead < b[0].length) {
+ byte[] out = new byte[totalBytesRead];
+ System.arraycopy(b[0], 0, out, 0, totalBytesRead);
b[0] = out;
}
- if (bytesRead <= 0) {
- return(0);
- }
- return ((int)bytesRead);
+ return totalBytesRead;
} catch (IOException e) {