public final class FtpOutputStream extends OutputStream
Modifier and Type | Field and Description |
---|---|
(package private) Ftp |
client |
private FtpDataSocket |
data |
private OutputStream |
stream |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
private FtpDataSocket data
private OutputStream stream
public FtpOutputStream(FtpFile file) throws IOException
This constructor behaves similarly to
.FtpOutputStream(FtpFile,boolean)
file
- the file to be opened for writingIOException
- socket errorpublic FtpOutputStream(FtpFile file, boolean append) throws IOException
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.
file
- the file to be opened for writingappend
- if true, then bytes will be written to the
end of the file rather than the beginningIOException
- socket errorpublic FtpOutputStream(FtpFile file, FtpConnect connect, CoConsole console) throws IOException
This constructor behaves similarly to
.FtpOutputStream(FtpFile,FtpConnect,CoConsole,boolean)
file
- the file to be opened for writingconnect
- login detailsconsole
- message outputIOException
- socket errorpublic FtpOutputStream(FtpFile file, FtpConnect connect, CoConsole console, boolean append) throws IOException
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.
file
- the file to be opened for writingconnect
- login detailsconsole
- message outputappend
- if true, then bytes will be written to the
end of the file rather than the beginningIOException
- socket errorFtpOutputStream(FtpFile,boolean)
public void close() throws IOException
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.
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- socket errorpublic void write(int b) throws IOException
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.write
in class OutputStream
b
- the byte
.IOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void write(byte[] b) throws IOException
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)
.write
in class OutputStream
b
- the data.IOException
- if an I/O error occurs.write(byte[], int, int)
public void write(byte[] b, int off, int len) throws IOException
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.
write
in class OutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.IOException
- if an I/O error occurs. In particular,
an IOException
is thrown if the output
stream is closed.public void flush() throws IOException
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.flush
in interface Flushable
flush
in class OutputStream
IOException
- if an I/O error occurs.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses