src/net/java/sip/communicator/impl/protocol/jabber/OperationSetFileTransferJabberImpl.java
/**
     * Sends a file transfer request to the given <tt>toContact</tt>.
     * @return the transfer object
     *
     * @param toContact the contact that should receive the file
     * @param file file to send
     */
Sends a file transfer request to the given toContact.
@return the transfer object

@param toContact the contact that should receive the file
@param file file to send
Sends a file transfer request to the given toContact . @return the transfer object @param toContact the contact that should receive the file @param file file to send
public FileTransfer sendFile(Contact toContact, File file)
        throws  IllegalStateException,
                IllegalArgumentException,
                OperationNotSupportedException
    {
        OutgoingFileTransferJabberImpl outgoingTransfer;
        try
        {
            assertConnected();
            if(file.length() > getMaximumFileLength())
                throw new IllegalArgumentException(
                    "File length exceeds the allowed one for this protocol");
            EntityFullJid fullJid = null;
            OperationSetMultiUserChat mucOpSet = jabberProvider
                .getOperationSet(OperationSetMultiUserChat.class);
            if(mucOpSet != null
                && mucOpSet.isPrivateMessagingContact(toContact.getAddress()))
            {
                fullJid = JidCreate.entityFullFrom(toContact.getAddress());
            }
            else
            {
                Jid jid = JidCreate.from(toContact.getAddress());
                Roster r = Roster.getInstanceFor(jabberProvider.getConnection());
                int bestPriority = -1;
                PresenceStatus jabberStatus = null;
                for (Presence presence : r.getPresences(jid.asBareJid()))
                {
                    if(jabberProvider.isFeatureListSupported(
                        presence.getFrom(),
                        "http://jabber.org/protocol/si",
                        "http://jabber.org/protocol/si/profile/file-transfer"))
                    {
                        int priority =
                            (presence.getPriority() == Integer.MIN_VALUE)
                                ? 0
                                : presence.getPriority();
                        if(priority > bestPriority)
                        {
                            bestPriority = priority;
                            fullJid = presence.getFrom().asEntityFullJidIfPossible();
                            jabberStatus = OperationSetPersistentPresenceJabberImpl
                                .jabberStatusToPresenceStatus(
                                    presence, jabberProvider);
                        }
                        else if(priority == bestPriority && jabberStatus != null)
                        {
                            PresenceStatus tempStatus =
                                OperationSetPersistentPresenceJabberImpl
                                   .jabberStatusToPresenceStatus(
                                       presence, jabberProvider);
                            if(tempStatus.compareTo(jabberStatus) > 0)
                            {
                                fullJid = presence.getFrom().asEntityFullJidIfPossible();
                                jabberStatus = tempStatus;
                            }
                        }
                    }
                }
            }
            if (fullJid == null)
            {
                throw new OperationNotSupportedException(
                    "Contact client or server does not support file transfers.");
            }
            FileTransferManager manager = FileTransferManager
                .getInstanceFor(jabberProvider.getConnection());
            OutgoingFileTransfer transfer
                = manager.createOutgoingFileTransfer(fullJid);
            outgoingTransfer
                = new OutgoingFileTransferJabberImpl(
                    toContact, file, transfer, jabberProvider);
            FileTransferCreatedEvent event
                = new FileTransferCreatedEvent(outgoingTransfer, new Date());
            fireFileTransferCreated(event);
            transfer.sendFile(file, "Sending file");
            new FileTransferProgressThread(
                transfer, outgoingTransfer).start();
        }
        catch(XmppStringprepException | SmackException e)
        {
            logger.error("Failed to send file.", e);
            throw new OperationNotSupportedException(
                "Could not start file transfer",
                e
            );
        }
        return outgoingTransfer;
    }
public FileTransfer sendFile ( Contact toContact , File file ) throws IllegalStateException , IllegalArgumentException , OperationNotSupportedException { OutgoingFileTransferJabberImpl outgoingTransfer ; try { assertConnected ( ) ; if ( file . length ( ) > getMaximumFileLength ( ) ) throw new IllegalArgumentException ( "File length exceeds the allowed one for this protocol" ) ; EntityFullJid fullJid = null ; OperationSetMultiUserChat mucOpSet = jabberProvider . getOperationSet ( OperationSetMultiUserChat . class ) ; if ( mucOpSet != null && mucOpSet . isPrivateMessagingContact ( toContact . getAddress ( ) ) ) { fullJid = JidCreate . entityFullFrom ( toContact . getAddress ( ) ) ; } else { Jid jid = JidCreate . from ( toContact . getAddress ( ) ) ; Roster r = Roster . getInstanceFor ( jabberProvider . getConnection ( ) ) ; int bestPriority = - 1 ; PresenceStatus jabberStatus = null ; for ( Presence presence : r . getPresences ( jid . asBareJid ( ) ) ) { if ( jabberProvider . isFeatureListSupported ( presence . getFrom ( ) , "http://jabber.org/protocol/si" , "http://jabber.org/protocol/si/profile/file-transfer" ) ) { int priority = ( presence . getPriority ( ) == Integer . MIN_VALUE ) ? 0 : presence . getPriority ( ) ; if ( priority > bestPriority ) { bestPriority = priority ; fullJid = presence . getFrom ( ) . asEntityFullJidIfPossible ( ) ; jabberStatus = OperationSetPersistentPresenceJabberImpl . jabberStatusToPresenceStatus ( presence , jabberProvider ) ; } else if ( priority == bestPriority && jabberStatus != null ) { PresenceStatus tempStatus = OperationSetPersistentPresenceJabberImpl . jabberStatusToPresenceStatus ( presence , jabberProvider ) ; if ( tempStatus . compareTo ( jabberStatus ) > 0 ) { fullJid = presence . getFrom ( ) . asEntityFullJidIfPossible ( ) ; jabberStatus = tempStatus ; } } } } } if ( fullJid == null ) { throw new OperationNotSupportedException ( "Contact client or server does not support file transfers." ) ; } FileTransferManager manager = FileTransferManager . getInstanceFor ( jabberProvider . getConnection ( ) ) ; OutgoingFileTransfer transfer = manager . createOutgoingFileTransfer ( fullJid ) ; outgoingTransfer = new OutgoingFileTransferJabberImpl ( toContact , file , transfer , jabberProvider ) ; FileTransferCreatedEvent event = new FileTransferCreatedEvent ( outgoingTransfer , new Date ( ) ) ; fireFileTransferCreated ( event ) ; transfer . sendFile ( file , "Sending file" ) ; new FileTransferProgressThread ( transfer , outgoingTransfer ) . start ( ) ; } catch ( XmppStringprepException | SmackException e ) { logger . error ( "Failed to send file." , e ) ; throw new OperationNotSupportedException ( "Could not start file transfer" , e ) ; } return outgoingTransfer ; }
Sends a file transfer request to the given <tt>toContact</tt>.
Sends a file transfer request to the given <tt > toContact< / tt > .
// Find the jid of the contact which support file transfer // and is with highest priority if more than one found // if we have equals priorities // choose the one that is more available // First we check if file transfer is at all supported for this // contact. // Notify all interested listeners that a file transfer has been // created. // Send the file through the Jabber file transfer. // Start the status and progress thread.