Smack

org.jivesoftware.smackx.filetransfer
Class FileTransferNegotiator

java.lang.Object
  extended by org.jivesoftware.smackx.filetransfer.FileTransferNegotiator

public class FileTransferNegotiator
extends Object

Manages the negotiation of file transfers according to JEP-0096. If a file is being sent the remote user chooses the type of stream under which the file will be sent.

Author:
Alexander Wenckus
See Also:
JEP-0096: File Transfer

Field Summary
static String BYTE_STREAM
          The XMPP namespace of the SOCKS5 bytestream
static boolean IBB_ONLY
          A static variable to use only offer IBB for file transfer.
static String INBAND_BYTE_STREAM
          The XMPP namespace of the In-Band bytestream
protected static String STREAM_DATA_FIELD_NAME
           
 
Method Summary
static IQ createIQ(String ID, String to, String from, IQ.Type type)
          A convience method to create an IQ packet.
static FileTransferNegotiator getInstanceFor(XMPPConnection connection)
          Returns the file transfer negotiator related to a particular connection.
 String getNextStreamID()
          Returns a new, unique, stream ID to identify a file transfer.
static Collection getSupportedProtocols()
          Returns a collection of the supported transfer protocols.
static boolean isServiceEnabled(XMPPConnection connection)
          Checks to see if all file transfer related services are enabled on the connection.
 StreamNegotiator negotiateOutgoingTransfer(String userID, String streamID, String fileName, long size, String desc, int responseTimeout)
          Send a request to another user to send them a file.
 void rejectStream(StreamInitiation si)
          Reject a stream initiation request from a remote user.
 StreamNegotiator selectStreamNegotiator(FileTransferRequest request)
          Selects an appropriate stream negotiator after examining the incoming file transfer request.
static void setServiceEnabled(XMPPConnection connection, boolean isEnabled)
          Enable the Jabber services related to file transfer on the particular connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_STREAM

public static final String BYTE_STREAM
The XMPP namespace of the SOCKS5 bytestream

See Also:
Constant Field Values

INBAND_BYTE_STREAM

public static final String INBAND_BYTE_STREAM
The XMPP namespace of the In-Band bytestream

See Also:
Constant Field Values

STREAM_DATA_FIELD_NAME

protected static final String STREAM_DATA_FIELD_NAME
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(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 IMFileTransferManager

setServiceEnabled

public static void setServiceEnabled(XMPPConnection connection,
                                     boolean isEnabled)
Enable the Jabber services related to file transfer on the particular connection.

Parameters:
connection - The connection on which to enable or disable the services.
isEnabled - True to enable, false to disable.

isServiceEnabled

public static boolean isServiceEnabled(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.

createIQ

public static IQ createIQ(String ID,
                          String to,
                          String from,
                          IQ.Type type)
A convience method to create an IQ packet.

Parameters:
ID - The packet ID of the
to - To whom the packet is addressed.
from - From whom the packet is sent.
type - The iq type of the packet.
Returns:
The created IQ packet.

getSupportedProtocols

public static Collection getSupportedProtocols()
Returns a collection of the supported transfer protocols.

Returns:
Returns a collection of the supported transfer protocols.

selectStreamNegotiator

public StreamNegotiator selectStreamNegotiator(FileTransferRequest request)
                                        throws XMPPException
Selects an appropriate stream negotiator after examining the incoming file transfer request.

Parameters:
request - The related file transfer request.
Returns:
The file transfer object that handles the transfer
Throws:
XMPPException - If there are either no stream methods contained in the packet, or there is not an appropriate stream method.

rejectStream

public void rejectStream(StreamInitiation si)
Reject a stream initiation request from a remote user.

Parameters:
si - The Stream Initiation request to reject.

getNextStreamID

public 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(String userID,
                                                  String streamID,
                                                  String fileName,
                                                  long size,
                                                  String desc,
                                                  int responseTimeout)
                                           throws XMPPException
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 packet will contain the other user's choosen 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 prefered 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 JEP-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:
XMPPException - Thrown if there is an error negotiating the file transfer.

Smack

Copyright © 2003-2007 Jive Software.