com.maverick.sftp
Class SftpFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.maverick.sftp.SftpFileInputStream
All Implemented Interfaces:
java.io.Closeable

public class SftpFileInputStream
extends java.io.InputStream

An InputStream to read the contents of a remote file.

 // Create an SshClient forcing SSH2 connectivity.
 SshConnector con = SshConnector.getInstance();
 con.setSupportedVersions(SshConnector.SSH2);

 // Connect and authenticate an SshClient
 Ssh2Client ssh = (Ssh2Client) con.connect(....);
 ....
 
 SftpClient sftp=new SftpClient(ssh);
 
 //read file as input stream
                InputStream in = sftp.getInputStream("streamTest");
                
                 // Read the data
                 int read;
                 while((read = in.read()) > -1){
                        //do something with data
                 }

                 // Close the file and the stream
                 in.close();

Author:
Lee David Painter

Constructor Summary
SftpFileInputStream(SftpFile file)
           
SftpFileInputStream(SftpFile file, long position)
          Creates a new SftpFileInputStream object.
 
Method Summary
 void close()
          Closes the SFTP file handle.
protected  void finalize()
          This method will only be available in J2SE builds
 int read()
           
 int read(byte[] buffer, int offset, int len)
           
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SftpFileInputStream

public SftpFileInputStream(SftpFile file)
                    throws SftpStatusException,
                           SshException
Parameters:
file -
Throws:
SftpStatusException
SshException

SftpFileInputStream

public SftpFileInputStream(SftpFile file,
                           long position)
                    throws SftpStatusException,
                           SshException
Creates a new SftpFileInputStream object.

Parameters:
file -
position - at which to start reading
Throws:
SftpStatusException
SshException
Method Detail

read

public int read(byte[] buffer,
                int offset,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the SFTP file handle.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

finalize

protected void finalize()
                 throws java.io.IOException
This method will only be available in J2SE builds

Overrides:
finalize in class java.lang.Object
Throws:
java.io.IOException


Copyright © 2003-2008 SSHTools LTD. All Rights Reserved.