From 35e225d1377bd5cac88af503e767cb0a1cb6eee7 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Sat, 30 Jul 2022 14:20:01 +0800 Subject: [PATCH] SFTPProxyFileDescriptorCallback: support read of size > 32768 --- .../safsftp/SFTPProxyFileDescriptorCallback.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java b/src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java index 8c1fc46..0c99f09 100644 --- a/src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java +++ b/src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java @@ -3,6 +3,7 @@ package org.safsftp; import android.os.ProxyFileDescriptorCallback; import android.system.ErrnoException; import android.system.OsConstants; +import android.util.Log; import java.io.IOException; @@ -31,7 +32,18 @@ public class SFTPProxyFileDescriptorCallback extends ProxyFileDescriptorCallback @Override public int onRead(long offset, int size, byte[] data) throws ErrnoException { try { - return sftp.read(file, offset, data, 0, size); + Log.v("SFTP", "r: " + size + "@" + offset); + int doff = 0; + while (doff < size) { + int batch = (size - doff) > 32768 ? 32768 : (size - doff); + int r = sftp.read(file, offset + doff, data, doff, batch); + Log.v("SFTP", "pr: " + batch + "@" + (offset + doff) + "=" + r); + doff += r; + if (r == -1) { + return doff; + } + } + return size; } catch (IOException e) { throw new ErrnoException("read", OsConstants.EIO); } -- 2.43.0