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:
commit
e5d9487b2e
3 changed files with 21 additions and 21 deletions
|
@ -17,6 +17,7 @@
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
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.JingleSession;
|
||||||
import org.jivesoftware.smackx.jingle.component.JingleTransport;
|
import org.jivesoftware.smackx.jingle.component.JingleTransport;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
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.util.Role;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.adapter.JingleFileTransferAdapter;
|
import org.jivesoftware.smackx.jingle_filetransfer.adapter.JingleFileTransferAdapter;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.component.JingleFile;
|
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.");
|
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(to, getNamespace())) {
|
FileInputStream fi = new FileInputStream(file);
|
||||||
throw new SmackException.FeatureNotSupportedException(getNamespace(), to);
|
|
||||||
}
|
|
||||||
|
|
||||||
JingleSession session = jingleManager.createSession(Role.initiator, to);
|
return sendStream(fi, metadata, 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutgoingFileOfferController sendStream(final InputStream stream, JingleFile metadata, FullJid recipient) throws SmackException.FeatureNotSupportedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
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);
|
content.setDescription(outgoingFileOffer);
|
||||||
|
|
||||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(recipient);
|
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);
|
JingleTransport<?> transport = transportManager.createTransportForInitiator(content);
|
||||||
content.setTransport(transport);
|
content.setTransport(transport);
|
||||||
|
|
||||||
|
|
|
@ -64,13 +64,17 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer implements
|
||||||
throw new IllegalStateException("Target OutputStream is null");
|
throw new IllegalStateException("Target OutputStream is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
state = State.active;
|
if (state == State.negotiating) {
|
||||||
|
state = State.active;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
HashElement hashElement = metadata.getHashElement();
|
HashElement hashElement = metadata.getHashElement();
|
||||||
MessageDigest digest = null;
|
MessageDigest digest = null;
|
||||||
if (hashElement != null) {
|
if (hashElement != null) {
|
||||||
digest = HashManager.getMessageDigest(hashElement.getAlgorithm());
|
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");
|
LOGGER.log(Level.INFO, "Receive file");
|
||||||
|
@ -87,6 +91,9 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer implements
|
||||||
int read = 0;
|
int read = 0;
|
||||||
byte[] bufbuf = new byte[4096];
|
byte[] bufbuf = new byte[4096];
|
||||||
while ((length = inputStream.read(bufbuf)) >= 0) {
|
while ((length = inputStream.read(bufbuf)) >= 0) {
|
||||||
|
if (getState() == State.cancelled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
target.write(bufbuf, 0, length);
|
target.write(bufbuf, 0, length);
|
||||||
read += length;
|
read += length;
|
||||||
LOGGER.log(Level.INFO, "Read " + read + " (" + length + ") of " + metadata.getSize() + " bytes.");
|
LOGGER.log(Level.INFO, "Read " + read + " (" + length + ") of " + metadata.getSize() + " bytes.");
|
||||||
|
|
|
@ -67,6 +67,9 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer implements
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
if (getState() == State.cancelled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
int r = source.read(buf);
|
int r = source.read(buf);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -80,7 +83,7 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer implements
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Exception while sending file: " + e, e);
|
LOGGER.log(Level.SEVERE, "Exception while sending file: " + e, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
state = State.ended;
|
||||||
try {
|
try {
|
||||||
source.close();
|
source.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in a new issue