Java 类org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer 实例源码

项目:system_updater    文件:Bot.java   
private void sendFile(String to,String file){
    /*
     * This sends a file to someone
     * @param to the xmmp-account who receives the file, the destination  
     * @param file the path from the file
     */
    File f=new File(file);
    FileTransferManager manager = new FileTransferManager(conn);
    OutgoingFileTransfer transfer =
            manager.createOutgoingFileTransfer(to);

    // Send the file
    try {
        transfer.sendFile(f,"I have a file for you?");
    } catch (XMPPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sendMessage(logAccount,"Sorry,couldn't deliver the file");
    }

}
项目:spark-svn-mirror    文件:FileTransferPreference.java   
public void commit() {
    LocalPreferences pref = SettingsManager.getLocalPreferences();

    String downloadDir = ui.getDownloadDirectory();
    if (ModelUtil.hasLength(downloadDir)) {
        pref.setDownloadDir(downloadDir);
    }

    String timeout = ui.getTimeout();
    if (ModelUtil.hasLength(timeout)) {
        int tout = 1;
        try {
            tout = Integer.parseInt(timeout);
        } catch (NumberFormatException e) {
            // Nothing to do
        }

        pref.setFileTransferTimeout(tout);

        final int timeOutMs = tout * (60 * 1000);
        OutgoingFileTransfer.setResponseTimeout(timeOutMs);
    }

    SettingsManager.saveSettings();

}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 向其他用户发送文件
 * @param xmppConnection
 * @param toUser 接受文件的用户名
 * @param fileName 文件路径
 * @param remark 备注
 * @return
 */
public static boolean sendFileToUser(XMPPConnection xmppConnection,String toUser,String fileName,String remark){
    // 创建文件传输管理器
    FileTransferManager manager = new FileTransferManager(xmppConnection);
    // 创建输出的文件传输
    OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(toUser);
    // 发送文件
    try {
        transfer.sendFile(new File(fileName), remark);
        return  true;
    } catch (XMPPException e) {
        e.printStackTrace();
        return  false;
    }
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 向其他用户发送文件
 * @param xmppConnection
 * @param toUser 接受文件的用户名
 * @param fileName 文件路径
 * @param remark 备注
 * @return
 */
public static boolean sendFileToUser(XMPPConnection xmppConnection,String toUser,String fileName,String remark){
    // 创建文件传输管理器
    FileTransferManager manager = new FileTransferManager(xmppConnection);
    // 创建输出的文件传输
    OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(toUser);
    // 发送文件
    try {
        transfer.sendFile(new File(fileName), remark);
        return  true;
    } catch (XMPPException e) {
        e.printStackTrace();
        return  false;
    }
}
项目:commune    文件:OutgoingTransfersManager.java   
/**
 * Default constructor. Initialize fields and sets the default detection
 * time of an outgoing file transfer.
 * 
 * @param maxOut maximum number of simultaneous outgoing file transfers
 */
public OutgoingTransfersManager( FileTransferManager manager, int maxOut, int responseTimeout, ReentrantLock transfersLock) {

    this.maxOut = maxOut;
    transfers = new ConcurrentHashMap<TransferHandle,OutgoingTransfer>();
    this.transfersLock = transfersLock;
    queuedTransfers = new LinkedList<OutgoingTransfer>();
    // Setting negotiation timeout
    OutgoingFileTransfer.setResponseTimeout( responseTimeout );
    this.manager = manager;
    transferStateMonitor = new TransferStateMonitorThread();
}
项目:commune    文件:OutgoingTransfersManager.java   
public void startTransfer(OutgoingTransferHandle handle, DeploymentID listenerID, Module module) {

        File file = handle.getLocalFile();
        DeploymentID destination = handle.getDestinationID();
        long inactivityTimeout = handle.getInactivityTimeout();
        boolean receiveProgressUpdates = handle.isReceiveProgressUpdate();
        String transferDescription = handle.getDescription();

        final OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer( destination.getContainerID().toString() );

        OutgoingTransfer fileTransfer = new OutgoingTransfer(module, listenerID, handle, transfer, file, 
                destination.toString(), inactivityTimeout, receiveProgressUpdates, transferDescription);

        if ( receiveProgressUpdates ) {
            TransferProgress transferProgress = 
                new TransferProgress(handle, file.getName(), file.length(), transfer.getStatus(), 0L, 0D, 0, true);
            Message message = 
                AbstractTransfer.createUpdateTransferProgressMessage(module.getContainerID(), listenerID, 
                        transferProgress);
            module.sendMessage(message);
        }

        try {
            transfersLock.lock();
            if ( transfers.size() < maxOut ) {
                activateTransfer( fileTransfer );
            } else {
                LOG.debug( "Queueing outgoing transfer of file " + file.getName() + ", handle: " + handle );
                queuedTransfers.offer( fileTransfer );
            }
        } finally {
            transfersLock.unlock();
        }
    }
项目:commune    文件:OutgoingTransfer.java   
public OutgoingTransfer(Module module, DeploymentID listenerID, TransferHandle handle, OutgoingFileTransfer transfer,
                                File file, String destinationDeploymentID, long inactivityTimeout, 
                                boolean notifyProgress, String transferDescription) {

    super(module, listenerID, inactivityTimeout, handle, file, file.length(), notifyProgress);
    this.transfer = transfer;
    this.destinationDeploymentID = destinationDeploymentID;
    this.transferDescription = transferDescription;
}
项目:XMPPSample_Studio    文件:LiveApp.java   
public void putFileTransferOut(String path, OutgoingFileTransfer fileTransfer) {
    fileTransfersOut.put(path, fileTransfer);
}
项目:XMPPSample_Studio    文件:LiveApp.java   
public OutgoingFileTransfer getFileTransferOut(String path) {
    return fileTransfersOut.get(path);
}
项目:hypergraphdb    文件:XMPPPeerInterface.java   
public PeerRelatedActivityFactory newSendActivityFactory()
{
    return new PeerRelatedActivityFactory() {
        public PeerRelatedActivity createActivity()
        {
            return new PeerRelatedActivity()
            {
                public Boolean call() throws Exception
                {

                    Json msg = getMessage();
                    if (!msg.has(Messages.REPLY_TO))
                    {
                        msg.set(Messages.REPLY_TO, connection.getUser());
                    }                        
                    String msgAsString = msg.toString();
                    if (msgAsString.length() > fileTransferThreshold)
                    {
                        OutgoingFileTransfer outFile = 
                            fileTransfer.createOutgoingFileTransfer((String)getTarget());
                        byte [] B = msgAsString.getBytes();
                        outFile.sendStream(new ByteArrayInputStream(B), 
                                           "", 
                                           B.length, 
                                           "");
                        return true;
                    }
                    else
                    {
                        try
                        {
                            Message xmpp = new Message((String)getTarget());                            
                            xmpp.setBody(msgAsString);
                            xmpp.setProperty("hypergraphdb", Boolean.TRUE);
                            connection.sendPacket(xmpp);                            
                            return true;
                        }
                        catch (Throwable t)
                        {
                            t.printStackTrace(System.err);
                            return false;
                        }
                    }
                }                    
            };
        }
    };
}
项目:yiim_v2    文件:FileUpload.java   
/**
     * 发送文件
     * 
     * @param connection
     * @param user
     * @param toUserName
     * @param file
     */
    public static void sendFile(final Context context,
            final Connection connection, final String toUser, final Uri uri,
            final String filePath, final MsgType msgType) {
        new Thread() {
            public void run() {
                XMPPConnection.DEBUG_ENABLED = true;
                // AccountManager accountManager;
                try {
                    // accountManager = connection.getAccountManager();
                    Presence pre = connection.getRoster().getPresence(toUser);
                    if (pre.getType() != Presence.Type.unavailable) {
                        if (connection.isConnected()) {
                            Log.d(TAG, "connection con");
                        }
                        // 创建文件传输管理器
//                      ServiceDiscoveryManager sdm = ServiceDiscoveryManager
//                              .getInstanceFor(connection);
//                      if (sdm == null)
//                          sdm = new ServiceDiscoveryManager(connection);

                        FileTransferManager manager = new FileTransferManager(
                                connection);
                        // 创建输出的文件传输
                        OutgoingFileTransfer transfer = manager
                                .createOutgoingFileTransfer(pre.getFrom());
                        // 发送文件
                        transfer.sendFile(new File(filePath),
                                msgType.toString());
                        while (!transfer.isDone()) {
                            if (transfer.getStatus() == FileTransfer.Status.in_progress) {
                                // 可以调用transfer.getProgress();获得传输的进度 
                                // Log.d(TAG,
                                // "send status:" + transfer.getStatus());
                                // Log.d(TAG,
                                // "send progress:"
                                // + transfer.getProgress());
                                if (mFileUploadListener != null) {
                                    mFileUploadListener.transProgress(context,
                                            uri, filePath,
                                            transfer.getProgress());
                                }
                            }
                        }
                        // YiLog.getInstance().i("send file error: %s",
                        // transfer.);
                        Log.d(TAG, "send status 1 " + transfer.getStatus());
                        if (transfer.isDone()) {
                            if (mFileUploadListener != null) {
                                mFileUploadListener.transDone(context, toUser,
                                        uri, msgType, filePath,
                                        transfer.getStatus());
                            }
                        }
                    }
                } catch (Exception e) {
                    Log.d(TAG, "send exception");
                    if (mFileUploadListener != null) {
                        mFileUploadListener.transDone(context, toUser, uri,
                                msgType, filePath, Status.error);
                    }
                }
            }
        }.start();
    }
项目:aceim    文件:XMPPFileTransferListener.java   
private OutgoingFileRunnable(List<File> files, OutgoingFileTransfer transfer, String receiverJid) {
    this.files = files;
    this.transfer = transfer;
    this.receiverJid = receiverJid;
}
项目:spark-svn-mirror    文件:SendFileTransfer.java   
private void updateBar(final OutgoingFileTransfer transfer, String nickname, String kBperSecond) {
    FileTransfer.Status status = transfer.getStatus();
    if (status == Status.negotiating_stream) {
        titleLabel.setText(Res.getString("message.negotiation.file.transfer", nickname));
    }
    else if (status == Status.error) {
        if (transfer.getException() != null) {
            Log.error("Error occured during file transfer.", transfer.getException());
        }
        progressBar.setVisible(false);
        progressLabel.setVisible(false);
        titleLabel.setText(Res.getString("message.unable.to.send.file", nickname));
        cancelButton.setVisible(false);
        retryButton.setVisible(true);
        showAlert(true);
    }
    else if (status == Status.in_progress) {
        titleLabel.setText(Res.getString("message.sending.file.to", nickname));
        showAlert(false);
        if (!progressBar.isVisible()) {
            progressBar.setVisible(true);
            progressLabel.setVisible(true);
        }

        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    // 100 % = Filesize
                // x %   = Currentsize      
                    long p = (transfer.getBytesSent() * 100 / transfer.getFileSize() );
                    progressBar.setValue(Math.round(p));
                }
            });
        }
        catch (Exception e) {
            Log.error(e);
        }

        ByteFormat format = new ByteFormat();
        String bytesSent = format.format(transfer.getBytesSent());
        String est = TransferUtils.calculateEstimate(transfer.getBytesSent(), transfer.getFileSize(), _starttime, System.currentTimeMillis());

        progressLabel.setText(Res.getString("message.transfer.progressbar.text.sent", bytesSent, kBperSecond, est));
    }
    else if (status == Status.complete) {
        progressBar.setVisible(false);

        String fin = TransferUtils.convertSecondstoHHMMSS(Math.round(System.currentTimeMillis()-_starttime)/1000);
        progressLabel.setText(Res.getString("label.time", fin));
        titleLabel.setText(Res.getString("message.you.have.sent", nickname));
        cancelButton.setVisible(false);
        showAlert(true);
    }
    else if (status == Status.cancelled) {
        progressBar.setVisible(false);
        progressLabel.setVisible(false);
        titleLabel.setText(Res.getString("message.file.transfer.canceled"));
        cancelButton.setVisible(false);
        retryButton.setVisible(true);
        showAlert(true);
    }
    else if (status == Status.refused) {
        progressBar.setVisible(false);
        progressLabel.setVisible(false);
        titleLabel.setText(Res.getString("message.file.transfer.rejected", nickname));
        cancelButton.setVisible(false);
        retryButton.setVisible(true);
        showAlert(true);
    }

}
项目:aceim    文件:XMPPFileTransferListener.java   
long sendFile(final String receiverJid, final List<File> files) {

    final OutgoingFileTransfer transfer = mFileTransferManager.createOutgoingFileTransfer(receiverJid);

    Runnable r = new OutgoingFileRunnable(files, transfer, receiverJid);
    Executors.defaultThreadFactory().newThread(r).start();

    return transfer.getStreamID().hashCode();
}
项目:spark-svn-mirror    文件:FileTransferPreference.java   
public FileTransferPreference() {
    localPreferences = SettingsManager.getLocalPreferences();
    int timeout = localPreferences.getFileTransferTimeout();

    timeout = timeout * 60 * 1000;

    OutgoingFileTransfer.setResponseTimeout(timeout);

    ui = new FileTransferPreferencePanel();
}