gnodet commented on a change in pull request #123:
URL: https://github.com/apache/mina-sshd/pull/123#discussion_r411687971



##########
File path: 
sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/impl/SftpRemotePathChannel.java
##########
@@ -346,30 +355,19 @@ public long transferTo(long position, long count, 
WritableByteChannel target) th
         }
 
         boolean completed = false;
-        boolean eof = false;
-        long curPos = position;
-        int bufSize = (int) Math.min(count, copySize);
-        byte[] buffer = new byte[bufSize];
-        long totalRead = 0L;
+        boolean eof;
+        long totalRead;
 
         synchronized (lock) {
             try {
                 beginBlocking("transferTo");
 
-                while (totalRead < count && !eof) {
-                    int read = sftp.read(handle, curPos, buffer, 0,
-                            (int) Math.min(count - totalRead, buffer.length));
-                    if (read > 0) {
-                        ByteBuffer wrap = ByteBuffer.wrap(buffer, 0, read);
-                        while (wrap.remaining() > 0) {
-                            target.write(wrap);
-                        }
-                        curPos += read;
-                        totalRead += read;
-                    } else {
-                        eof = read == -1;
-                    }
-                }
+                SftpInputStreamAsync input = new SftpInputStreamAsync(
+                        (AbstractSftpClient) sftp,
+                        copySize, position, count, getRemotePath(), handle);

Review comment:
       Calling `close` has 2 effects: blocking until the stream is fully 
consumed and closing the handle.  In this particular usage, the data is already 
consumed in the `transferTo` and we don't want to close the handle.  The 
`close` implementation is really focused on the standard usage of the 
`InputStream`, not this internal usage.  
   If that really sounds too hacky, we can always use two different classes 
through inheritance, but I thought the comment would be sufficient. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to