Package org.apache.mina.common

Examples of org.apache.mina.common.ByteBuffer.flip()


        buf.putShort((short) type);
        buf.putInt(m.getSequence());

        // Encode a body
        encodeBody(session, m, buf);
        buf.flip();
        out.write(buf);
    }

    protected abstract void encodeBody(IoSession session,
            AbstractMessage message, ByteBuffer out);
View Full Code Here


        ByteBuffer rb = (ByteBuffer) message;
        // Write the received data back to remote peer
        ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
        wb.put(rb);
        wb.flip();
        session.write(wb);
    }
}
View Full Code Here

            //System.out.println("\n+++++++");
        } catch (CharacterCodingException ex) {
            ex.printStackTrace();
        }

        buf.flip();
        out.write(buf);
    }

    public Set<Class<?>> getMessageTypes() {
        return TYPES;
View Full Code Here

     */
    void filterSend(FilterListener listener, byte[] message) {
        ByteBuffer buffer = ByteBuffer.allocate(message.length + 2, false);
        buffer.putShort((short) message.length);
        buffer.put(message);
        buffer.flip();
        // Don't worry about the listener throwing an exception, since
        // this method has no other side effects.
        listener.sendUnfiltered(buffer);
    }
}
View Full Code Here

            return new ProtocolEncoder() {
                public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput out)
                    throws Exception {
                    ByteBuffer bb = ByteBuffer.allocate(9).setAutoExpand(true);
                    bb.put("Bye World".getBytes());
                    bb.flip();
                    out.write(bb);
                }

                public void dispose(IoSession ioSession) throws Exception {
                    // do nothing
View Full Code Here

            codecFactory = new ProtocolCodecFactory() {
                public ProtocolEncoder getEncoder() throws Exception {
                    return new ProtocolEncoder() {
                        public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
                            ByteBuffer buf = toByteBuffer(message);
                            buf.flip();
                            out.write(buf);
                        }

                        public void dispose(IoSession session) throws Exception {
                            // do nothing
View Full Code Here

        {
            buf.release();
            throw new IllegalArgumentException( "The encoded object is too big: " + objectSize + " (> " + maxObjectSize + ')' );
        }
       
        buf.flip();
        out.write( buf );
    }
}
View Full Code Here

            ByteBuffer rb = (ByteBuffer) message;
            // Write the received data back to remote peer
            ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
            wb.put(rb);
            wb.flip();
            session.write(wb);
        }
    }
}
View Full Code Here

        TestDecoderOutput out = new TestDecoderOutput();
        ByteBuffer in = ByteBuffer.allocate(16);

        // Test one decode and one output
        in.putString("ABC\r\n", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(1, out.getMessageQueue().size());
        Assert.assertEquals("ABC", out.getMessageQueue().poll());

        // Test two decode and one output
View Full Code Here

        Assert.assertEquals("ABC", out.getMessageQueue().poll());

        // Test two decode and one output
        in.clear();
        in.putString("DEF", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("GHI\r\n", encoder);
        in.flip();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.