org.jivesoftware.smackx.filetransfer.FileTransferManager Java Examples

The following examples show how to use org.jivesoftware.smackx.filetransfer.FileTransferManager. 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: FileDownloadListener.java    From yiim_v2 with GNU General Public License v2.0 6 votes vote down vote up
public FileDownloadListener(Context context, Connection connection) {
	this.mConnection = connection;
	this.mContext = context;
	recieveFilePath = YiFileUtils.getStorePath() + "yiim/"
			+ UserInfo.getUserInfo(context).getUserName() + "/file_recv/";

	// ServiceDiscoveryManager sdm = ServiceDiscoveryManager
	// .getInstanceFor(connection);
	// if (sdm == null)
	// sdm = new ServiceDiscoveryManager(connection);
	// sdm.addFeature("http://jabber.org/protocol/disco#info");
	// sdm.addFeature("jabber:iq:privacy");
	FileTransferManager transfer = new FileTransferManager(connection);
	FileTransferNegotiator.setServiceEnabled(connection, true);
	transfer.addFileTransferListener(new RecFileTransferListener());
}
 
Example #2
Source File: XmppConnection.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 发送文件
 * 
 * @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 #3
Source File: XMPPFileTransferManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: XmppFileService.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #5
Source File: IbbFile.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
public IbbFile() {
	// TODO Auto-generated constructor stub

	ibbmanager = InBandBytestreamManager.getByteStreamManager(Launcher.connection);
	ibbmanager.setDefaultBlockSize(61440);

	final FileTransferManager manager = FileTransferManager.getInstanceFor(Launcher.connection);
	// Create the listener
	//manager.addFileTransferListener(li);
}
 
Example #6
Source File: FileUpload.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * 发送文件
	 * 
	 * @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 #7
Source File: XMPPFileTransferManager.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}