Package org.apache.mina.core.buffer

Examples of org.apache.mina.core.buffer.IoBuffer.rewind()


        while (buffer.hasRemaining()) {
            decoder.decode(session, buffer, out);
        }
        buffer = IoBuffer.allocate(0).setAutoExpand(true);
        buffer.putString("B", encoder);
        buffer.rewind();
        while (buffer.hasRemaining()) {
            decoder.decode(session, buffer, out);
        }
        assertEquals(4, out.getMessageQueue().size());
        assertTrue(out.getMessageQueue().poll() instanceof HttpRequest);
View Full Code Here


            public void flush(NextFilter nextFilter, IoSession session) {
            }
        };
        IoBuffer buffer = IoBuffer.allocate(0).setAutoExpand(true);
        buffer.putString("GET / HTTP/1.0\r\nHost:localhost\r\n\r\n", encoder);
        buffer.rewind();
        while (buffer.hasRemaining()) {
            decoder.decode(session, buffer, out);
        }
        assertEquals(2, out.getMessageQueue().size());
        HttpRequest request = (HttpRequest) out.getMessageQueue().poll();
View Full Code Here

            public void flush(NextFilter nextFilter, IoSession session) {
            }
        };
        IoBuffer buffer = IoBuffer.allocate(0).setAutoExpand(true);
        buffer.putString("GET / HTTP/1.0\r\nHost:  localhost\r\n\r\n", encoder);
        buffer.rewind();
        while (buffer.hasRemaining()) {
            decoder.decode(session, buffer, out);
        }
        assertEquals(2, out.getMessageQueue().size());
        HttpRequest request = (HttpRequest) out.getMessageQueue().poll();
View Full Code Here

            public void flush(NextFilter nextFilter, IoSession session) {
            }
        };
        IoBuffer buffer = IoBuffer.allocate(0).setAutoExpand(true);
        buffer.putString("GET / HTTP/1.0\r\nHost:localhost  \r\n\r\n", encoder);
        buffer.rewind();
        while (buffer.hasRemaining()) {
            decoder.decode(session, buffer, out);
        }
        assertEquals(2, out.getMessageQueue().size());
        HttpRequest request = (HttpRequest) out.getMessageQueue().poll();
View Full Code Here

            @Override
            public void sessionOpened(IoSession session) throws Exception {
                IoBuffer buffer = IoBuffer.allocate(1);
                buffer.put((byte) 125);
                buffer.rewind();
                session.write(buffer);
            }
           
        });
        acceptor.bind(new InetSocketAddress(port));
View Full Code Here

 
  public static void main(String[] args) {
    IoBuffer buf=IoBuffer.allocate(10);
    buf.putChar('i');
    System.out.println(buf);
    buf.rewind();
    System.out.println(buf);
  }
}
View Full Code Here

        // length is the data minus 4 bytes for the pre-pended length
        int recordLength = buf.position() - 4;

        // write the length
        buf.rewind();
        buf.putInt( recordLength );

        // set the position back before flipping the buffer
        buf.position( pos );
        buf.flip();
View Full Code Here

        // length is the data minus 2 bytes for the pre-pended length
        short recordLength = ( short ) ( end - 2 );

        // write the length
        buf.rewind();
        buf.putShort( recordLength );

        // set the position back before flipping the buffer
        buf.position( end );
        buf.flip();
View Full Code Here

        @Override
        public void messageSent(IoSession session, Object message)
                throws Exception {
            IoBuffer buffer = (IoBuffer) message;
            buffer.rewind();
            byte[] data = new byte[buffer.remaining()];
            buffer.get(data);
            StringBuffer sb = (StringBuffer) session.getAttribute("sent");
            sb.append(new String(data, "ASCII"));
        }
View Full Code Here

    }

    private static boolean checkRequest(IoBuffer message) {
        IoBuffer buff = message;
        boolean check = buff.get() == 1;
        buff.rewind();
        return check;
    }

    private static boolean checkResponse(IoBuffer message) {
        IoBuffer buff = message;
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.