Package com.enterprisedt.net.ftp
Class FTPInputStream
java.lang.Object
java.io.InputStream
com.enterprisedt.net.ftp.FileTransferInputStream
com.enterprisedt.net.ftp.FTPInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Represents an input stream of bytes coming from an FTP server, permitting
the user to download a file by reading the stream. It can only be used
for one download, i.e. after the stream is closed it cannot be reopened.
- Version:
- $Revision$
- Author:
- Bruce Blackshaw
-
Field Summary
Fields inherited from class com.enterprisedt.net.ftp.FileTransferInputStream
closed, monitor, monitorCount, monitorEx, monitorInterval, pos, remoteFile, started -
Constructor Summary
ConstructorsConstructorDescriptionFTPInputStream(FTPClient client, String remoteFile) Constructor.FTPInputStream(FTPClient client, String remoteFile, long offset) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this input stream and releases any system resources associated with the stream.voidmark(int readlimit) Marks the current position in this input stream.booleanTests if this input stream supports themarkandresetmethods.intread()Reads the next byte of data from the input stream.intread(byte[] b, int off, int len) Reads up to len bytes of data from the input stream into an array of bytes.voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.voidsetMonitor(FTPProgressMonitorEx monitor, long monitorInterval) The input stream uses the progress monitor currently owned by the FTP client.longskip(long n) Skips over and discardsnbytes of data from this input stream.Methods inherited from class com.enterprisedt.net.ftp.FileTransferInputStream
checkMonitor, getRemoteFileMethods inherited from class java.io.InputStream
available, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
FTPInputStream
Constructor. A connected FTPClient instance must be supplied. This sets up the download- Parameters:
client- connected FTPClient instanceremoteFile- remote file- Throws:
IOExceptionFTPException
-
FTPInputStream
public FTPInputStream(FTPClient client, String remoteFile, long offset) throws IOException, FTPException Constructor. A connected FTPClient instance must be supplied. This sets up the download. If an offset > 0 is supplied, must be a binary transfer.- Parameters:
client- connected FTPClient instanceremoteFile- remote fileoffset- offset to resume downloading from.- Throws:
IOExceptionFTPException
-
-
Method Details
-
setMonitor
The input stream uses the progress monitor currently owned by the FTP client. This method allows a different progress monitor to be passed in, or for the monitor interval to be altered.- Overrides:
setMonitorin classFileTransferInputStream- Parameters:
monitor- progress monitor referencemonitorInterval-
-
read
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Specified by:
readin classInputStream- Throws:
IOException
-
read
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.- Overrides:
readin classInputStream- Parameters:
b- array to read intooff- offset into the array to start atlen- the number of bytes to be read- Returns:
- the number of bytes read, or -1 if the end of the stream has been reached.
- Throws:
IOException
-
close
Closes this input stream and releases any system resources associated with the stream. This must be called before any other operations are initiated on the FTPClient.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if an I/O error occurs.
-
skip
Skips over and discardsnbytes of data from this input stream. Theskipmethod may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0. This may result from any of a number of conditions; reaching end of file beforenbytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifnis negative, no bytes are skipped.- Overrides:
skipin classInputStream- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if the stream does not support seek, or if some other I/O error occurs.
-
mark
public void mark(int readlimit) Marks the current position in this input stream. A subsequent call to theresetmethod repositions this stream at the last marked position so that subsequent reads re-read the same bytes.- Overrides:
markin classInputStream- Parameters:
readlimit- the maximum limit of bytes that can be read before the mark position becomes invalid.- See Also:
-
reset
Repositions this stream to the position at the time themarkmethod was last called on this input stream.- Overrides:
resetin classInputStream- Throws:
IOException- if this stream has not been marked or if the mark has been invalidated.- See Also:
-
markSupported
public boolean markSupported()Tests if this input stream supports themarkandresetmethods. Whether or notmarkandresetare supported is an invariant property of a particular input stream instance. ThemarkSupportedmethod ofInputStreamreturnsfalse.- Overrides:
markSupportedin classInputStream- Returns:
trueif this stream instance supports the mark and reset methods;falseotherwise.- See Also:
-