~xdavidwu/saf-sftp

35e225d1377bd5cac88af503e767cb0a1cb6eee7 — xdavidwu 1 year, 8 months ago 44d8e23
SFTPProxyFileDescriptorCallback: support read of size > 32768
1 files changed, 13 insertions(+), 1 deletions(-)

M src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java
M src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java => src/main/java/org/safsftp/SFTPProxyFileDescriptorCallback.java +13 -1
@@ 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);
		}