com.maverick.sftp
Class SftpFileOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bycom.maverick.sftp.SftpFileOutputStream

public class SftpFileOutputStream
extends java.io.OutputStream

An OutputStream to write data to 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(....);
 ....

 // Create and initialize an SftpSubsystemChannel
 SftpSubsystemChannel sftp = new SftpSubsystemChannel(65535, 32768);
 ssh.openChannel(sftp);
 sftp.initialize();

 SftpFile file = sftp.openFile("foo", SftpSubsystemChannel.OPEN_WRITE
                                      | SftpSubsystemChannel.OPEN_CREATE);
 SftpFileOutputStream out = new SftpFileOutputStream(file);

 // Read the data
 ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes());
 int read;
 while((read = in.read()) > -1)
   out.write(read);

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

Author:
Lee David Painter

Constructor Summary
SftpFileOutputStream(SftpFile file)
          Creates a new SftpFileOutputStream object.
 
Method Summary
 void close()
          Closes the file's handle
protected  void finalize()
          This method will only be available in J2SE builds
 void write(byte[] buffer, int offset, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SftpFileOutputStream

public SftpFileOutputStream(SftpFile file)
                     throws SftpStatusException,
                            SshException
Creates a new SftpFileOutputStream object.

Parameters:
file -
Throws:
SftpStatusException
SshException
Method Detail

write

public void write(byte[] buffer,
                  int offset,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Throws:
java.io.IOException

close

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

Throws:
java.io.IOException

finalize

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

Throws:
java.io.IOException


Copyright © 2003 3SP LTD. All Rights Reserved.