org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer Java Examples
The following examples show how to use
org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppConnection.java From weixin with Apache License 2.0 | 6 votes |
/** * 发送文件 * * @param user * @param filePath */ public void sendFile(String user, String filePath) { if (getConnection() == null) return; // 创建文件传输管理器 FileTransferManager manager = new FileTransferManager(getConnection()); // 创建输出的文件传输 OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(user); // 发送文件 try { transfer.sendFile(new File(filePath), "You won't believe this!"); } catch (XMPPException e) { e.printStackTrace(); } }
Example #2
Source File: XMPPFileTransferManager.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Start sending a file to a contact. * * <p>This method will return while the transfer negotiation is processing. Use {@link * XMPPFileTransfer#waitForTransferStart(java.util.function.BooleanSupplier)} to wait till the * negotiation is done. * * @param remoteJID fully qualified JID of remote * @param file the file itself * @param description description can be null, used as identifier for incoming transfer * @return {@link XMPPFileTransfer} providing information about the transfer * @throws IllegalArgumentException if provided JID is not fully qualified * @throws IOException if no connection is available or XMPP related error */ public XMPPFileTransfer fileSendStart(JID remoteJID, File file, String description) throws IllegalArgumentException, IOException { if (remoteJID == null || remoteJID.isBareJID()) throw new IllegalArgumentException("No valid remoteJID provided: " + remoteJID); FileTransferManager currentManager = smackTransferManager.get(); if (currentManager == null) throw new IOException("No XMPP connection."); try { OutgoingFileTransfer transfer = currentManager.createOutgoingFileTransfer(remoteJID.getRAW()); transfer.sendFile(file, description); return new XMPPFileTransfer(transfer); } catch (XMPPException e) { throw new IOException("File send to " + remoteJID + " failed.", e); } }
Example #3
Source File: XmppFileService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
public static void sendFile(String fileFullPath,String fulljid,String description) { // TODO: 通知服务器要开始在线上传文件 FileTransferManager manager = FileTransferManager.getInstanceFor(Launcher.connection); OutgoingFileTransfer transfer; try { transfer = manager.createOutgoingFileTransfer(JidCreate.entityFullFrom(fulljid)); transfer.sendFile(new File(fileFullPath), description); } catch (XmppStringprepException | SmackException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #4
Source File: XMPPFileTransferManager.java From saros with GNU General Public License v2.0 | 5 votes |
public XMPPFileTransferManager( XMPPConnectionService connectionService, XMPPContactsService contactsService) { connectionService.addListener(connectionListener); this.contactsService = contactsService; // smack only allows a global response timeout OutgoingFileTransfer.setResponseTimeout(GLOBAL_SMACK_RESPONSE_TIMEOUT); }
Example #5
Source File: FileTransferPreference.java From Spark with Apache License 2.0 | 5 votes |
@Override public void commit() { LocalPreferences pref = SettingsManager.getLocalPreferences(); pref.setFileTransferIbbOnly(ui.getIbbOnly()); 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(); }
Example #6
Source File: LiveApp.java From XMPPSample_Studio with Apache License 2.0 | 4 votes |
public void putFileTransferOut(String path, OutgoingFileTransfer fileTransfer) { fileTransfersOut.put(path, fileTransfer); }
Example #7
Source File: LiveApp.java From XMPPSample_Studio with Apache License 2.0 | 4 votes |
public OutgoingFileTransfer getFileTransferOut(String path) { return fileTransfersOut.get(path); }
Example #8
Source File: XMPPPeerInterface.java From hypergraphdb with Apache License 2.0 | 4 votes |
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; } } } }; } }; }
Example #9
Source File: FileUpload.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
/** * 发送文件 * * @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(); }
Example #10
Source File: SendFileTransfer.java From Spark with Apache License 2.0 | 4 votes |
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( () -> { // 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); } }
Example #11
Source File: XMPPFileTransferManager.java From saros with GNU General Public License v2.0 | 3 votes |
/** * Start a file stream with a contact. * * <p>This method will return while the transfer negotiation is processing. Use {@link * XMPPFileTransfer#waitForTransferStart(java.util.function.BooleanSupplier)} to wait till the * negotiation is done. * * @param remoteJID fully qualified JID of remote * @param streamName identifier of the stream * @param inputStream InputStream to send data from * @return {@link XMPPFileTransfer} providing information about the transfer * @throws IllegalArgumentException if provided JID is not fully qualified * @throws IOException if no connection is available or XMPP related error */ public XMPPFileTransfer streamSendStart(JID remoteJID, String streamName, InputStream inputStream) throws IllegalArgumentException, IOException { if (remoteJID == null || remoteJID.isBareJID()) throw new IllegalArgumentException("No valid remoteJID provided: " + remoteJID); FileTransferManager currentManager = smackTransferManager.get(); if (currentManager == null) throw new IOException("No XMPP connection."); OutgoingFileTransfer transfer = currentManager.createOutgoingFileTransfer(remoteJID.getRAW()); transfer.sendStream(inputStream, streamName, 0, streamName); return new XMPPFileTransfer(transfer); }
Example #12
Source File: FileTransferPreference.java From Spark with Apache License 2.0 | 3 votes |
public FileTransferPreference() { localPreferences = SettingsManager.getLocalPreferences(); int timeout = localPreferences.getFileTransferTimeout(); timeout = timeout * 60 * 1000; OutgoingFileTransfer.setResponseTimeout(timeout); ui = new FileTransferPreferencePanel(); }