Class FileTransferNegotiator


  • public final class FileTransferNegotiator
    extends org.jivesoftware.smack.Manager
    Manages the negotiation of file transfers according to XEP-0096. If a file is being sent the remote user chooses the type of stream under which the file will be sent.
    See Also:
    XEP-0096: SI File Transfer
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static FileTransferNegotiator getInstanceFor​(org.jivesoftware.smack.XMPPConnection connection)
      Returns the file transfer negotiator related to a particular connection.
      static java.lang.String getNextStreamID()
      Returns a new, unique, stream ID to identify a file transfer.
      static java.util.Collection<java.lang.String> getSupportedProtocols()
      Returns a collection of the supported transfer protocols.
      static boolean isServiceEnabled​(org.jivesoftware.smack.XMPPConnection connection)
      Checks to see if all file transfer related services are enabled on the connection.
      StreamNegotiator negotiateOutgoingTransfer​(org.jxmpp.jid.Jid userID, java.lang.String streamID, java.lang.String fileName, long size, java.lang.String desc, int responseTimeout)
      Send a request to another user to send them a file.
      StreamNegotiator selectStreamNegotiator​(FileTransferRequest request)
      Selects an appropriate stream negotiator after examining the incoming file transfer request.
      • Methods inherited from class org.jivesoftware.smack.Manager

        connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SI_PROFILE_FILE_TRANSFER_NAMESPACE

        public static final java.lang.String SI_PROFILE_FILE_TRANSFER_NAMESPACE
        See Also:
        Constant Field Values
      • IBB_ONLY

        public static boolean IBB_ONLY
        A static variable to use only offer IBB for file transfer. It is generally recommend to only set this variable to true for testing purposes as IBB is the backup file transfer method and shouldn't be used as the only transfer method in production systems.
    • Method Detail

      • getInstanceFor

        public static FileTransferNegotiator getInstanceFor​(org.jivesoftware.smack.XMPPConnection connection)
        Returns the file transfer negotiator related to a particular connection. When this class is requested on a particular connection the file transfer service is automatically enabled.
        Parameters:
        connection - The connection for which the transfer manager is desired
        Returns:
        The FileTransferNegotiator
      • isServiceEnabled

        public static boolean isServiceEnabled​(org.jivesoftware.smack.XMPPConnection connection)
        Checks to see if all file transfer related services are enabled on the connection.
        Parameters:
        connection - The connection to check
        Returns:
        True if all related services are enabled, false if they are not.
      • getSupportedProtocols

        public static java.util.Collection<java.lang.String> getSupportedProtocols()
        Returns a collection of the supported transfer protocols.
        Returns:
        Returns a collection of the supported transfer protocols.
      • getNextStreamID

        public static java.lang.String getNextStreamID()
        Returns a new, unique, stream ID to identify a file transfer.
        Returns:
        Returns a new, unique, stream ID to identify a file transfer.
      • negotiateOutgoingTransfer

        public StreamNegotiator negotiateOutgoingTransfer​(org.jxmpp.jid.Jid userID,
                                                          java.lang.String streamID,
                                                          java.lang.String fileName,
                                                          long size,
                                                          java.lang.String desc,
                                                          int responseTimeout)
                                                   throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                          org.jivesoftware.smack.SmackException.NotConnectedException,
                                                          org.jivesoftware.smack.SmackException.NoResponseException,
                                                          FileTransferException.NoAcceptableTransferMechanisms,
                                                          java.lang.InterruptedException
        Send a request to another user to send them a file. The other user has the option of, accepting, rejecting, or not responding to a received file transfer request.

        If they accept, the stanza will contain the other user's chosen stream type to send the file across. The two choices this implementation provides to the other user for file transfer are SOCKS5 Bytestreams, which is the preferred method of transfer, and In-Band Bytestreams, which is the fallback mechanism.

        The other user may choose to decline the file request if they do not desire the file, their client does not support XEP-0096, or if there are no acceptable means to transfer the file.

        Finally, if the other user does not respond this method will return null after the specified timeout.
        Parameters:
        userID - The userID of the user to whom the file will be sent.
        streamID - The unique identifier for this file transfer.
        fileName - The name of this file. Preferably it should include an extension as it is used to determine what type of file it is.
        size - The size, in bytes, of the file.
        desc - A description of the file.
        responseTimeout - The amount of time, in milliseconds, to wait for the remote user to respond. If they do not respond in time, this
        Returns:
        Returns the stream negotiator selected by the peer.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - Thrown if there is an error negotiating the file transfer.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        FileTransferException.NoAcceptableTransferMechanisms - if no acceptable transfer mechanisms are available
        java.lang.InterruptedException - if the calling thread was interrupted.