Class FileTransferManager
- java.lang.Object
-
- rocks.xmpp.core.session.Manager
-
- rocks.xmpp.extensions.filetransfer.FileTransferManager
-
public final class FileTransferManager extends Manager
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFileTransferOfferListener(Consumer<FileTransferOfferEvent> fileTransferOfferListener)
Adds a file transfer listener, which allows to listen for inbound file transfer requests.void
fileTransferOffered(IQ iq, String sessionId, String mimeType, FileTransferOffer fileTransferOffer, Object protocol, FileTransferNegotiator fileTransferNegotiator)
static String
md5Hash(Path source)
Calculates the MD5 hash for a file.AsyncResult<FileTransfer>
offerFile(File file, String description, Jid recipient, Duration timeout)
Offers a file to another user.AsyncResult<FileTransfer>
offerFile(InputStream source, String fileName, long fileSize, Instant lastModified, String description, Jid recipient, Duration timeout)
Offers a stream to another user.AsyncResult<FileTransfer>
offerFile(InputStream source, String fileName, long fileSize, Instant lastModified, String description, Jid recipient, Duration timeout, String sessionId)
Offers a stream to another user.AsyncResult<FileTransfer>
offerFile(InputStream source, String fileName, long fileSize, Instant lastModified, String description, Jid recipient, Duration timeout, String sessionId, String mimeType, String hash)
Offers a stream to another user.AsyncResult<IQ>
offerFile(URI uri, String description, Jid recipient, Duration timeout)
Offers a file to another user in form of an URL.AsyncResult<FileTransfer>
offerFile(Path source, String description, Jid recipient, Duration timeout)
Offers a file to another user.AsyncResult<FileTransfer>
offerFile(Path source, String description, Jid recipient, Duration timeout, String mimeType, boolean calculateHash)
Offers a file to another user.void
removeFileTransferOfferListener(Consumer<FileTransferOfferEvent> fileTransferOfferListener)
Removes a previously added file transfer listener.-
Methods inherited from class rocks.xmpp.core.session.Manager
isEnabled, setEnabled
-
-
-
-
Method Detail
-
md5Hash
public static String md5Hash(Path source) throws IOException
Calculates the MD5 hash for a file. The returned string is hex encoded.- Parameters:
source
- The source path.- Returns:
- The hex encoded MD5 hash.
- Throws:
IOException
- If the file could not be read.
-
offerFile
public final AsyncResult<IQ> offerFile(URI uri, String description, Jid recipient, Duration timeout)
Offers a file to another user in form of an URL. The file can be downloaded by the recipient via an HTTP GET request. If this method returns without exception you can assume, that the file has been successfully downloaded by the recipient.- Parameters:
uri
- The URI of the file.description
- The description of the file.recipient
- The recipient's JID (must be a full JID).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).- Returns:
- The async result.
- See Also:
- XEP-0066: Out of Band Data
-
offerFile
public final AsyncResult<FileTransfer> offerFile(File file, String description, Jid recipient, Duration timeout) throws IOException
Offers a file to another user. If this method returns successfully, the recipient has accepted the offer, the stream method has been negotiated and the file is ready to be transferred. CallFileTransfer.transfer()
to start the file transfer.- Parameters:
file
- The file.description
- The description of the file.recipient
- The recipient's JID (must be a full JID, i. e. including resource).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).- Returns:
- The async result with the file transfer object.
- Throws:
IOException
- If the file can't be read.
-
offerFile
public final AsyncResult<FileTransfer> offerFile(Path source, String description, Jid recipient, Duration timeout) throws IOException
Offers a file to another user. If this method returns successfully, the recipient has accepted the offer, the stream method has been negotiated and the file is ready to be transferred. CallFileTransfer.transfer()
to start the file transfer.- Parameters:
source
- The file.description
- The description of the file.recipient
- The recipient's JID (must be a full JID, i. e. including resource).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).- Returns:
- The async result with the file transfer object.
- Throws:
IOException
- If the file can't be read.
-
offerFile
public final AsyncResult<FileTransfer> offerFile(Path source, String description, Jid recipient, Duration timeout, String mimeType, boolean calculateHash) throws IOException
Offers a file to another user. If this method returns successfully, the recipient has accepted the offer, the stream method has been negotiated and the file is ready to be transferred. CallFileTransfer.transfer()
to start the file transfer.- Parameters:
source
- The file.description
- The description of the file.recipient
- The recipient's JID (must be a full JID, i. e. including resource).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).mimeType
- The mime type. If null, the mime type is guessed.calculateHash
- If true, the MD5 hash for the file is calculated and included in the offer.- Returns:
- The async result with the file transfer object.
- Throws:
IOException
- If the file can't be read.
-
offerFile
public final AsyncResult<FileTransfer> offerFile(InputStream source, String fileName, long fileSize, Instant lastModified, String description, Jid recipient, Duration timeout)
Offers a stream to another user. If this method returns successfully, the recipient has accepted the offer, the stream method has been negotiated and the file is ready to be transferred. CallFileTransfer.transfer()
to start the file transfer.- Parameters:
source
- The stream.fileName
- The file name.fileSize
- The file size.lastModified
- The last modified date.description
- The description of the file.recipient
- The recipient's JID (must be a full JID, i. e. including resource).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).- Returns:
- The async result with the file transfer object.
-
offerFile
public final AsyncResult<FileTransfer> offerFile(InputStream source, String fileName, long fileSize, Instant lastModified, String description, Jid recipient, Duration timeout, String sessionId)
Offers a stream to another user. If this method returns successfully, the recipient has accepted the offer, the stream method has been negotiated and the file is ready to be transferred. CallFileTransfer.transfer()
to start the file transfer.- Parameters:
source
- The stream.fileName
- The file name.fileSize
- The file size.lastModified
- The last modified date.description
- The description of the file.recipient
- The recipient's JID (must be a full JID, i. e. including resource).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).sessionId
- The session id.- Returns:
- The async result with the file transfer object.
-
offerFile
public final AsyncResult<FileTransfer> offerFile(InputStream source, String fileName, long fileSize, Instant lastModified, String description, Jid recipient, Duration timeout, String sessionId, String mimeType, String hash)
Offers a stream to another user. If this method returns successfully, the recipient has accepted the offer, the stream method has been negotiated and the file is ready to be transferred. CallFileTransfer.transfer()
to start the file transfer.- Parameters:
source
- The stream.fileName
- The file name.fileSize
- The file size.lastModified
- The last modified date.description
- The description of the file.recipient
- The recipient's JID (must be a full JID, i. e. including resource).timeout
- The timeout (indicates how long to wait until the file offer has either been accepted or rejected).sessionId
- The session id.mimeType
- The mime type. If null, the mime type is guessed.hash
- The hash (maybe null). As per the specification this should be a hex-encoded MD5 hash.- Returns:
- The async result with the file transfer object.
- See Also:
md5Hash(Path)
-
fileTransferOffered
public void fileTransferOffered(IQ iq, String sessionId, String mimeType, FileTransferOffer fileTransferOffer, Object protocol, FileTransferNegotiator fileTransferNegotiator)
-
addFileTransferOfferListener
public void addFileTransferOfferListener(Consumer<FileTransferOfferEvent> fileTransferOfferListener)
Adds a file transfer listener, which allows to listen for inbound file transfer requests.- Parameters:
fileTransferOfferListener
- The listener.- See Also:
removeFileTransferOfferListener(Consumer)
-
removeFileTransferOfferListener
public void removeFileTransferOfferListener(Consumer<FileTransferOfferEvent> fileTransferOfferListener)
Removes a previously added file transfer listener.- Parameters:
fileTransferOfferListener
- The listener.- See Also:
addFileTransferOfferListener(Consumer)
-
-