You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2022/10/16 16:26:44 UTC

[openoffice] branch trunk 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.

damjan pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/trunk by this push:
     new f04910427d InputStreamToXInputStreamAdapter.readBytes() should read until the buffer is full, or the file ends. It shouldn't care about available().
f04910427d is described below

commit f04910427d25ede98b84b90df7cc5a12d1adc695
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
---
 .../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) {