本文整理汇总了Java中org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer类的典型用法代码示例。如果您正苦于以下问题:Java OutgoingFileTransfer类的具体用法?Java OutgoingFileTransfer怎么用?Java OutgoingFileTransfer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OutgoingFileTransfer类属于org.jivesoftware.smackx.filetransfer包,在下文中一共展示了OutgoingFileTransfer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFile
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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");
}
}
示例2: output
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
public void output(String jid) throws XMPPException{
FileTransferManager manager = new FileTransferManager(connection);
// Create the outgoing file transfer
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(jid); //����û�ҪΪ �����jid��[email protected]/resource
// Send the file
InputStream inputStream;
try {
inputStream = context.getResources().getAssets().open("xmpp.txt");
transfer.sendStream(inputStream, "xmpp.txt", inputStream.available(), "aa");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: commit
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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();
}
示例4: sendFileToUser
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
/**
* 向其他用户发送文件
* @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;
}
}
示例5: OutgoingTransfersManager
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
/**
* 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();
}
示例6: startTransfer
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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();
}
}
示例7: OutgoingTransfer
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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;
}
示例8: putFileTransferOut
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
public void putFileTransferOut(String path, OutgoingFileTransfer fileTransfer) {
fileTransfersOut.put(path, fileTransfer);
}
示例9: getFileTransferOut
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
public OutgoingFileTransfer getFileTransferOut(String path) {
return fileTransfersOut.get(path);
}
示例10: newSendActivityFactory
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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;
}
}
}
};
}
};
}
示例11: sendFile
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
/**
* 发送文件
*
* @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();
}
示例12: OutgoingFileRunnable
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
private OutgoingFileRunnable(List<File> files, OutgoingFileTransfer transfer, String receiverJid) {
this.files = files;
this.transfer = transfer;
this.receiverJid = receiverJid;
}
示例13: updateBar
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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);
}
}
示例14: sendFile
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
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();
}
示例15: FileTransferPreference
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; //导入依赖的package包/类
public FileTransferPreference() {
localPreferences = SettingsManager.getLocalPreferences();
int timeout = localPreferences.getFileTransferTimeout();
timeout = timeout * 60 * 1000;
OutgoingFileTransfer.setResponseTimeout(timeout);
ui = new FileTransferPreferencePanel();
}