Class FileTransfer
- java.lang.Object
-
- rocks.xmpp.extensions.filetransfer.FileTransfer
-
public final class FileTransfer extends Object
A class for managing a single file transfer. It allows to monitor the progress and status of a file transfer by adding a listener.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileTransfer.Status
The status of the file transfer.
-
Constructor Summary
Constructors Constructor Description FileTransfer(String sessionId, InputStream inputStream, OutputStream outputStream, long length)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFileTransferStatusListener(Consumer<FileTransferStatusEvent> fileTransferStatusListener)
Adds a file transfer status listener, which allows to listen for file transfer status changes.void
cancel()
Cancels the file transfer.long
getBytesTransferred()
Gets the transferred bytes.Exception
getException()
Gets the exception if the status isFileTransfer.Status.FAILED
double
getProgress()
Gets the progress of the file transfer.String
getSessionId()
Gets the session id for this file transfer session.FileTransfer.Status
getStatus()
Gets the status of the file transfer.boolean
isDone()
Returns true, if the file transfer is done, i.e. neither in progress nor in initial status.void
removeFileTransferStatusListener(Consumer<FileTransferStatusEvent> fileTransferStatusListener)
Removes a previously added file transfer status listener.Future<?>
transfer()
Transfers the file in its own thread.
-
-
-
Constructor Detail
-
FileTransfer
public FileTransfer(String sessionId, InputStream inputStream, OutputStream outputStream, long length)
-
-
Method Detail
-
addFileTransferStatusListener
public final void addFileTransferStatusListener(Consumer<FileTransferStatusEvent> fileTransferStatusListener)
Adds a file transfer status listener, which allows to listen for file transfer status changes.- Parameters:
fileTransferStatusListener
- The listener.- See Also:
removeFileTransferStatusListener(Consumer)
-
removeFileTransferStatusListener
public final void removeFileTransferStatusListener(Consumer<FileTransferStatusEvent> fileTransferStatusListener)
Removes a previously added file transfer status listener.- Parameters:
fileTransferStatusListener
- The listener.- See Also:
addFileTransferStatusListener(Consumer)
-
getStatus
public final FileTransfer.Status getStatus()
Gets the status of the file transfer.- Returns:
- The status.
-
isDone
public final boolean isDone()
Returns true, if the file transfer is done, i.e. neither in progress nor in initial status.- Returns:
- True, if the file transfer is done.
-
getBytesTransferred
public long getBytesTransferred()
Gets the transferred bytes.- Returns:
- The transferred bytes.
-
getProgress
public final double getProgress()
Gets the progress of the file transfer.- Returns:
- A value between 0 and 1 indicating the progress or -1 if the progress is unknown.
-
transfer
public final Future<?> transfer()
Transfers the file in its own thread.- Returns:
- The future which is done when transferring is complete.
-
cancel
public void cancel()
Cancels the file transfer.
-
getSessionId
public final String getSessionId()
Gets the session id for this file transfer session.- Returns:
- The session id.
-
getException
public final Exception getException()
Gets the exception if the status isFileTransfer.Status.FAILED
- Returns:
- The exception or null.
-
-