Java Code Examples for org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager#getByteStreamManager()

The following examples show how to use org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager#getByteStreamManager() . 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: 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 2
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 3
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 4
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 5
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);
}