Class FileTransferManager


  • public final class FileTransferManager
    extends Manager
    • 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. Call FileTransfer.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. Call FileTransfer.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. Call FileTransfer.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. Call FileTransfer.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. Call FileTransfer.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. Call FileTransfer.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)