org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager Java Examples

The following examples show how to use org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JingleIBBTransportSession.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public void initiateIncomingSession(final JingleTransportInitiationCallback callback) {
    LOGGER.log(Level.INFO, "Await Jingle InBandBytestream session.");

    InBandBytestreamManager.getByteStreamManager(jingleSession.getConnection()).addIncomingBytestreamListener(new BytestreamListener() {
        @Override
        public void incomingBytestreamRequest(BytestreamRequest request) {
            if (request.getFrom().asFullJidIfPossible().equals(jingleSession.getRemote())
                    && request.getSessionID().equals(theirProposal.getSessionId())) {
                BytestreamSession session;

                try {
                    session = request.accept();
                } catch (InterruptedException | SmackException | XMPPException.XMPPErrorException e) {
                    callback.onException(e);
                    return;
                }
                callback.onSessionInitiated(session);
            }
        }
    });
}
 
Example #2
Source File: IbbFile.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
public IbbFile() {
	// TODO Auto-generated constructor stub

	ibbmanager = InBandBytestreamManager.getByteStreamManager(Launcher.connection);
	ibbmanager.setDefaultBlockSize(61440);

	final FileTransferManager manager = FileTransferManager.getInstanceFor(Launcher.connection);
	// Create the listener
	//manager.addFileTransferListener(li);
}
 
Example #3
Source File: JingleIBBTransportSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public void initiateOutgoingSession(JingleTransportInitiationCallback callback) {
    LOGGER.log(Level.INFO, "Initiate Jingle InBandBytestream session.");

    BytestreamSession session;
    try {
        session = InBandBytestreamManager.getByteStreamManager(jingleSession.getConnection())
                .establishSession(jingleSession.getRemote(), theirProposal.getSessionId());
        callback.onSessionInitiated(session);
    } catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
        callback.onException(e);
    }
}
 
Example #4
Source File: IBBStreamService.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void initialize(
    Connection connection, IByteStreamConnectionListener listener) {
  localAddress = new JID(connection.getUser());
  connectionListener = listener;
  manager = InBandBytestreamManager.getByteStreamManager(connection);
  manager.addIncomingBytestreamListener(this);
}
 
Example #5
Source File: IBBTransferNegotiator.java    From Smack with Apache License 2.0 4 votes vote down vote up
private ByteStreamRequest(InBandBytestreamManager manager, Open byteStreamRequest) {
    super(manager, byteStreamRequest);
}
 
Example #6
Source File: InBandBytestreamTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * An In-Band Bytestream should be successfully established using IQ stanzas.
 *
 * @throws Exception should not happen
 */
public void testInBandBytestreamWithIQStanzas() throws Exception {

    XMPPConnection initiatorConnection = getConnection(0);
    XMPPConnection targetConnection = getConnection(1);

    // test data
    Random rand = new Random();
    final byte[] data = new byte[dataSize];
    rand.nextBytes(data);
    final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();

    InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);

    InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {

        public void incomingBytestreamRequest(InBandBytestreamRequest request) {
            InputStream inputStream;
            try {
                inputStream = request.accept().getInputStream();
                byte[] receivedData = new byte[dataSize];
                int totalRead = 0;
                while (totalRead < dataSize) {
                    int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
                    totalRead += read;
                }
                queue.put(receivedData);
            }
            catch (Exception e) {
                fail(e.getMessage());
            }
        }

    };
    targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);

    InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);

    OutputStream outputStream = initiatorByteStreamManager.establishSession(
                    targetConnection.getUser()).getOutputStream();

    // verify stream
    outputStream.write(data);
    outputStream.flush();
    outputStream.close();

    assertEquals("received data not equal to sent data", data, queue.take());

}
 
Example #7
Source File: InBandBytestreamTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * An In-Band Bytestream should be successfully established using message stanzas.
 *
 * @throws Exception should not happen
 */
public void testInBandBytestreamWithMessageStanzas() throws Exception {

    XMPPConnection initiatorConnection = getConnection(0);
    XMPPConnection targetConnection = getConnection(1);

    // test data
    Random rand = new Random();
    final byte[] data = new byte[dataSize];
    rand.nextBytes(data);
    final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();

    InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);

    InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {

        public void incomingBytestreamRequest(InBandBytestreamRequest request) {
            InputStream inputStream;
            try {
                inputStream = request.accept().getInputStream();
                byte[] receivedData = new byte[dataSize];
                int totalRead = 0;
                while (totalRead < dataSize) {
                    int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
                    totalRead += read;
                }
                queue.put(receivedData);
            }
            catch (Exception e) {
                fail(e.getMessage());
            }
        }

    };
    targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);

    InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
    initiatorByteStreamManager.setStanza(StanzaType.MESSAGE);

    OutputStream outputStream = initiatorByteStreamManager.establishSession(
                    targetConnection.getUser()).getOutputStream();

    // verify stream
    outputStream.write(data);
    outputStream.flush();
    outputStream.close();

    assertEquals("received data not equal to sent data", data, queue.take());

}
 
Example #8
Source File: IBBTransferNegotiator.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * The default constructor for the In-Band Bytestream Negotiator.
 *
 * @param connection The connection which this negotiator works on.
 */
protected IBBTransferNegotiator(XMPPConnection connection) {
    super(connection);
    this.manager = InBandBytestreamManager.getByteStreamManager(connection);
}