xmpp_sync/src/main/java/de/vanitasvitae/sync_client/Slave.java

27 lines
1.0 KiB
Java
Raw Normal View History

2017-08-11 13:47:54 +02:00
package de.vanitasvitae.sync_client;
import java.io.File;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jft.JingleFileTransferManager;
import org.jxmpp.stringprep.XmppStringprepException;
public class Slave extends Client {
public Slave(String username, String password, String dir) throws XmppStringprepException {
super(username, password, dir);
JingleFileTransferManager jingleFileTransferManager = JingleFileTransferManager.getInstanceFor(connection);
jingleFileTransferManager.addIncomingFileOfferListener(offer -> {
try {
File target = new File(root.toFile(), offer.getFile().getName());
target.getParentFile().mkdirs();
offer.accept(connection, target);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NoResponseException | SmackException.NotConnectedException e) {
e.printStackTrace();
}
});
}
}