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()); }
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"); } }
/** * 向其他用户发送文件 * @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; } }
/** * Instantiates a new file share system. * * @param deviceID * the device id * @param localCacheDirectory * the local cache directory */ public FileShareSystem(String deviceID, File localCacheDirectory) { this.deviceID = deviceID; fileShareDelegatesByContentID = new HashMap<MD5Hash, FileShareSystemContentRegistrationDelegate>(); this.localFileCache = new LocalFileCache(localCacheDirectory); FileTransferNegotiator.IBB_ONLY = true; fileReceiver = new FileReceiver(this, this.localFileCache); fileTransferManager = new FileTransferManager(SynergyNetCluster.get().getXMPPConnection()); log.fine("Registering fileReceiver with file transfer manager"); fileTransferManager.addFileTransferListener(fileReceiver); messagingManager = SynergyNetCluster.get().getMessagingManager(); messagingManager.registerMessageListener(this, FileDistributionMessage.class); }
@Override public void newConnection(XMPPConnection connection) { // disable streamhost prioritization Socks5BytestreamManager s5bsm = Socks5BytestreamManager.getBytestreamManager(connection); s5bsm.setProxyPrioritizationEnabled(false); sFileTransferManager = FileTransferManager.getInstanceFor(connection); sFileTransferManager.addFileTransferListener(this); }
/** * 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(); }
public IncomingTransfersManager(Module module, FileTransferManager manager, ReentrantLock transfersLock) { this.module = module; receiverListeners = new HashMap<DeploymentID,TransferReceiver>(); handlersRequestMap = new HashMap<IncomingTransferHandle,FileTransferRequest>(); transfers = new ConcurrentHashMap<TransferHandle,IncomingTransfer>(); this.manager = manager; transferStateMonitor = new TransferStateMonitorThread(); this.transfersLock = transfersLock; }
public void start(Module module, XMPPConnection connection) { ReentrantLock lock = new ReentrantLock(); FileTransferManager manager = new FileTransferManager(connection); incomingManager = new IncomingTransfersManager(module, manager, lock); int responseTimeout = context.parseIntegerProperty(TransferProperties.PROP_FILE_TRANSFER_TIMEOUT) * 1000; outgoingManager = new OutgoingTransfersManager(manager, maxOut, responseTimeout, lock); incomingManager.start(connection); outgoingManager.start(); }
/** * 发送文件 * * @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(); }
/** * @return the mFileTransferManager */ public FileTransferManager getFileTransferManager() { return mFileTransferManager; }
/** * @param mFileTransferManager the mFileTransferManager to set */ public void setFileTransferManager(FileTransferManager mFileTransferManager) { this.mFileTransferManager = mFileTransferManager; }
/** * Instantiates a new file sender worker. * * @param localFileCache * the local file cache * @param fileTransferManager * the file transfer manager * @param deviceToSendToJID * the device to send to jid * @param identityOfFileToSend * the identity of file to send */ public FileSenderWorker(LocalFileCache localFileCache, FileTransferManager fileTransferManager, String deviceToSendToJID, MD5Hash identityOfFileToSend) { this.localFileCache = localFileCache; this.fileTransferManager = fileTransferManager; this.destinationDevice = deviceToSendToJID; this.identifyOfFile = identityOfFileToSend; }