Package org.apache.mina.common

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


        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("GHI\r\n", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(1, out.getMessageQueue().size());
        Assert.assertEquals("DEFGHI", out.getMessageQueue().poll());

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


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

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

        // Test splitted long delimiter
        decoder = new TextLineDecoder(Charset.forName("UTF-8"),
                new LineDelimiter("\n\n\n"));
        in.clear();
        in.putString("PQR\n", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("\n", encoder);
        in.flip();
View Full Code Here

        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("\n", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("\n", encoder);
        in.flip();
View Full Code Here

                        ByteBuffer rb = (ByteBuffer) message;
                        rb.mark();
                        byteCount = rb.remaining();
                        ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
                        wb.put(rb);
                        wb.flip();
                        rb.reset();
                        messageCopy = wb;
                    }

                    // Avoid unwanted side effect that scheduledWrite* becomes negative
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

                bb.putString(body, encoder);
                bb.put((byte) endByte1);
                bb.put((byte) endByte2);

                // flip the buffer so we can use it to write to the out stream
                bb.flip();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Encoding HL7 from " + message.getClass().getCanonicalName() + " to byte stream");
                }
                out.write(bb);
            }
View Full Code Here

                public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput out)
                    throws Exception {
                    ByteBuffer bb = ByteBuffer.allocate(32).setAutoExpand(true);
                    String s = (String) message;
                    bb.put(s.getBytes());
                    bb.flip();
                    out.write(bb);
                }

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

        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("\n", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(1, out.getMessageQueue().size());
        Assert.assertEquals("PQR", out.getMessageQueue().poll());

        // Test splitted long delimiter which produces two output
View Full Code Here

        // Test splitted long delimiter which produces two output
        decoder = new TextLineDecoder(Charset.forName("UTF-8"),
                new LineDelimiter("\n\n\n"));
        in.clear();
        in.putString("PQR\n", encoder);
        in.flip();
        decoder.decode(session, in, out);
        Assert.assertEquals(0, out.getMessageQueue().size());
        in.clear();
        in.putString("\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.