Package org.jivesoftware.smackx.bytestreams.ibb

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


        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();
View Full Code Here


        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();
View Full Code Here

        // mock connection
        Connection connection = mock(Connection.class);

        // initialize InBandBytestreamManager to get the DataListener
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);

        // get the DataListener from InBandByteStreamManager
        DataListener dataListener = Whitebox.getInternalState(byteStreamManager,
                        DataListener.class);
View Full Code Here

        // mock connection
        Connection connection = mock(Connection.class);

        // initialize InBandBytestreamManager to get the CloseListener
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);

        // get the CloseListener from InBandByteStreamManager
        CloseListener closeListener = Whitebox.getInternalState(byteStreamManager,
                        CloseListener.class);
View Full Code Here

        // mock two connections
        Connection connection1 = mock(Connection.class);
        Connection connection2 = mock(Connection.class);

        // get bytestream manager for the first connection twice
        InBandBytestreamManager conn1ByteStreamManager1 = InBandBytestreamManager.getByteStreamManager(connection1);
        InBandBytestreamManager conn1ByteStreamManager2 = InBandBytestreamManager.getByteStreamManager(connection1);

        // get bytestream manager for second connection
        InBandBytestreamManager conn2ByteStreamManager1 = InBandBytestreamManager.getByteStreamManager(connection2);

        // assertions
        assertEquals(conn1ByteStreamManager1, conn1ByteStreamManager2);
        assertNotSame(conn1ByteStreamManager1, conn2ByteStreamManager1);
View Full Code Here

     * throw an exception if the given target does not support in-band
     * bytestream.
     */
    @Test
    public void shouldFailIfTargetDoesNotSupportIBB() {
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);

        try {
            XMPPError xmppError = new XMPPError(
                            XMPPError.Condition.feature_not_implemented);
            IQ errorIQ = IBBPacketUtils.createErrorIQ(targetJID, initiatorJID, xmppError);
            protocol.addResponse(errorIQ);

            // start In-Band Bytestream
            byteStreamManager.establishSession(targetJID);

            fail("exception should be thrown");
        }
        catch (XMPPException e) {
            assertEquals(XMPPError.Condition.feature_not_implemented.toString(),
View Full Code Here

    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldNotAllowTooBigDefaultBlockSize() {
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
        byteStreamManager.setDefaultBlockSize(1000000);
    }
View Full Code Here

        byteStreamManager.setDefaultBlockSize(1000000);
    }

    @Test
    public void shouldCorrectlySetDefaultBlockSize() {
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
        byteStreamManager.setDefaultBlockSize(1024);
        assertEquals(1024, byteStreamManager.getDefaultBlockSize());
    }
View Full Code Here

        assertEquals(1024, byteStreamManager.getDefaultBlockSize());
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldNotAllowTooBigMaximumBlockSize() {
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
        byteStreamManager.setMaximumBlockSize(1000000);
    }
View Full Code Here

        byteStreamManager.setMaximumBlockSize(1000000);
    }

    @Test
    public void shouldCorrectlySetMaximumBlockSize() {
        InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
        byteStreamManager.setMaximumBlockSize(1024);
        assertEquals(1024, byteStreamManager.getMaximumBlockSize());
    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.