cz.dhl.ftp
Class FtpOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bycz.dhl.ftp.FtpOutputStream

public final class FtpOutputStream
extends java.io.OutputStream

Allows writing into FTP file.

Version:
0.72 08/10/2003
Author:
Bea Petrovicova
See Also:
Ftp, FtpFile

Constructor Summary
FtpOutputStream(FtpFile file)
          Opens 'store' OutputStream for given filename.
FtpOutputStream(FtpFile file, boolean append)
          Open either 'store' or 'append' OutputStream for given filename.
FtpOutputStream(FtpFile file, FtpConnect connect, CoConsole console)
          Opens 'store' concurent OutputStream for given filename.
FtpOutputStream(FtpFile file, FtpConnect connect, CoConsole console, boolean append)
          Open either 'store' or 'append' concurent OutputStream for given filename.
 
Method Summary
 void close()
          Close current data transfer and close data connection.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this output stream.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FtpOutputStream

public FtpOutputStream(FtpFile file)
                throws java.io.IOException
Opens 'store' OutputStream for given filename.

This constructor behaves similarly to FtpOutputStream(FtpFile,boolean).

Parameters:
file - the file to be opened for writing
Throws:
java.io.IOException - socket error

FtpOutputStream

public FtpOutputStream(FtpFile file,
                       boolean append)
                throws java.io.IOException
Open either 'store' or 'append' OutputStream for given filename.

STOR - store

This command causes the server-DTP to accept the data transferred via the data connection and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist.

APPE - append (with create)

This command causes the server-DTP to accept the data transferred via the data connection and to store the data in a file at the server site. If the file specified in the pathname exists at the server site, then the data shall be appended to that file; otherwise the file specified in the pathname shall be created at the server site.

Parameters:
file - the file to be opened for writing
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
java.io.IOException - socket error

FtpOutputStream

public FtpOutputStream(FtpFile file,
                       FtpConnect connect,
                       CoConsole console)
                throws java.io.IOException
Opens 'store' concurent OutputStream for given filename.

This constructor behaves similarly to FtpOutputStream(FtpFile,FtpConnect,CoConsole,boolean).

Parameters:
file - the file to be opened for writing
connect - login details
console - message output
Throws:
java.io.IOException - socket error

FtpOutputStream

public FtpOutputStream(FtpFile file,
                       FtpConnect connect,
                       CoConsole console,
                       boolean append)
                throws java.io.IOException
Open either 'store' or 'append' concurent OutputStream for given filename.

Single ftp connection cannot handle multiple concurent data transfers. This limitation can be eliminated by creating new ftp connection for each concurent data transfer. This constructor creates separate Ftp instance.

Note (1) supplying same CoConsole instance for multiple sessions will produce messed output.

Note (2) This code may need to be run in separate thread to process multiple files concurently.

STOR - store

This command causes the server-DTP to accept the data transferred via the data connection and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist.

APPE - append (with create)

This command causes the server-DTP to accept the data transferred via the data connection and to store the data in a file at the server site. If the file specified in the pathname exists at the server site, then the data shall be appended to that file; otherwise the file specified in the pathname shall be created at the server site.

Parameters:
file - the file to be opened for writing
connect - login details
console - message output
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
java.io.IOException - socket error
See Also:
FtpOutputStream(FtpFile,boolean)
Method Detail

close

public void close()
           throws java.io.IOException
Close current data transfer and close data connection.

If no reply ABOR - abort

This command tells the server to abort the previous FTP service command and any associated transfer of data. No action is to be taken if the previous command has been completed (including data transfer). The control connection is not to be closed by the server, but the data connection must be closed. There are two cases for the server upon receipt of this command:

(1) the FTP service command was already completed. The server closes the data connection (if it is open) and responds with a 226 reply, indicating that the abort command was successfully processed.

(2) the FTP service command is still in progress. The server aborts the FTP service in progress and closes the data connection, returning a 426 reply to indicate that the service request terminated abnormally. The server then sends a 226 reply, indicating that the abort command was successfully processed.

Throws:
java.io.IOException - socket error

flush

public void flush()
           throws java.io.IOException
Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(byte[] b)
           throws java.io.IOException
Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters:
b - the data.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
write(byte[], int, int)

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

The write method of OutputStream calls the write method of one argument on each of the bytes to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters:
b - the byte.
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.


Available from sourceforge http://sourceforge.net/projects/jvftp under the terms of GNU Lesser General Public License (LGPL).