1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-27 14:32:06 +01:00

Merge branch 'jftPR' into jetPR

This commit is contained in:
vanitasvitae 2017-08-22 14:45:55 +02:00
commit e5d9487b2e
3 changed files with 21 additions and 21 deletions

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.jingle_filetransfer;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@ -40,6 +41,7 @@ import org.jivesoftware.smackx.jingle.component.JingleContent;
import org.jivesoftware.smackx.jingle.component.JingleSession;
import org.jivesoftware.smackx.jingle.component.JingleTransport;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.util.Role;
import org.jivesoftware.smackx.jingle_filetransfer.adapter.JingleFileTransferAdapter;
import org.jivesoftware.smackx.jingle_filetransfer.component.JingleFile;
@ -106,25 +108,9 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
}
if (!ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(to, getNamespace())) {
throw new SmackException.FeatureNotSupportedException(getNamespace(), to);
}
FileInputStream fi = new FileInputStream(file);
JingleSession session = jingleManager.createSession(Role.initiator, to);
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
session.addContent(content);
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file, metadata);
content.setDescription(offer);
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(to);
JingleTransport<?> transport = transportManager.createTransportForInitiator(content);
content.setTransport(transport);
session.sendInitiate(connection());
return offer;
return sendStream(fi, metadata, to);
}
public OutgoingFileOfferController sendStream(final InputStream stream, JingleFile metadata, FullJid recipient) throws SmackException.FeatureNotSupportedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
@ -142,6 +128,10 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
content.setDescription(outgoingFileOffer);
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(recipient);
if (transportManager == null) {
//At least Jingle IBB should be supported.
throw new SmackException.FeatureNotSupportedException(JingleIBBTransport.NAMESPACE, recipient);
}
JingleTransport<?> transport = transportManager.createTransportForInitiator(content);
content.setTransport(transport);

View file

@ -64,13 +64,17 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer implements
throw new IllegalStateException("Target OutputStream is null");
}
if (state == State.negotiating) {
state = State.active;
} else {
return;
}
HashElement hashElement = metadata.getHashElement();
MessageDigest digest = null;
if (hashElement != null) {
digest = HashManager.getMessageDigest(hashElement.getAlgorithm());
LOGGER.log(Level.INFO, "File offer had checksum: " + digest.toString());
LOGGER.log(Level.INFO, "File offer had checksum: " + digest.toString() + ": " + hashElement.getHashB64());
}
LOGGER.log(Level.INFO, "Receive file");
@ -87,6 +91,9 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer implements
int read = 0;
byte[] bufbuf = new byte[4096];
while ((length = inputStream.read(bufbuf)) >= 0) {
if (getState() == State.cancelled) {
break;
}
target.write(bufbuf, 0, length);
read += length;
LOGGER.log(Level.INFO, "Read " + read + " (" + length + ") of " + metadata.getSize() + " bytes.");

View file

@ -67,6 +67,9 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer implements
byte[] buf = new byte[8192];
while (true) {
if (getState() == State.cancelled) {
break;
}
int r = source.read(buf);
if (r < 0) {
break;
@ -80,7 +83,7 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer implements
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Exception while sending file: " + e, e);
} finally {
state = State.ended;
try {
source.close();
} catch (IOException e) {