Author: ggregory
Date: Fri Apr 20 12:16:33 2012
New Revision: 1328346

URL: http://svn.apache.org/viewvc?rev=1328346&view=rev
Log:
[VFS-410][SFTP] SftpFileObject getInputStream(long) reads the whole file into 
memory.

Modified:
    
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java?rev=1328346&r1=1328345&r2=1328346&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
 (original)
+++ 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
 Fri Apr 20 12:16:33 2012
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.vfs2.provider.sftp;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -447,32 +445,21 @@ public class SftpFileObject extends Abst
 
     /**
      * Creates an input stream to read the file content from.
+     * The input stream is starting at the given position in the file.
      */
     InputStream getInputStream(long filePointer) throws IOException
     {
         final ChannelSftp channel = fileSystem.getChannel();
+        // Using InputStream directly from the channel
+        // is much faster than the memory method.
         try
         {
-            // hmmm - using the in memory method is soooo much faster ...
-            // TODO - Don't read the entire file into memory. Use the
-            // stream-based methods on ChannelSftp once they work properly 
final
-            // .... no stream based method with resume???
-            ByteArrayOutputStream outstr = new ByteArrayOutputStream();
-            try
-            {
-                channel.get(getName().getPathDecoded(), outstr, null,
-                        ChannelSftp.RESUME, filePointer);
-            }
-            catch (SftpException e)
-            {
-                throw new FileSystemException(e);
-            }
-            outstr.close();
-            return new ByteArrayInputStream(outstr.toByteArray());
-        }
-        finally
+            InputStream is = channel.get(getName().getPathDecoded(), null, 
filePointer);
+            return new SftpInputStream(channel, is);
+        } catch (SftpException e)
         {
             fileSystem.putChannel(channel);
+            throw new FileSystemException(e);
         }
     }
 

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1328346&r1=1328345&r2=1328346&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Fri Apr 20 12:16:33 2012
@@ -26,6 +26,9 @@
       <action issue="VFS-411" dev="ggregory" type="update" due-to="ggregory">
         [SFTP] Update Jsch to version 0.1.47 from 0.1.46.
       </action>
+      <action issue="VFS-410" dev="ggregory" type="fix" due-to="mstockhammer">
+        [SFTP] SftpFileObject getInputStream(long) reads the whole file into 
memory.
+      </action>
       <action issue="VFS-409" dev="ggregory" type="update" due-to="ggregory">
         Update Apache Commons Compress to 1.4 from 1.3.
       </action>


Reply via email to