Package net.sf.cindy

Examples of net.sf.cindy.Buffer.indexOf()


        }
        buffer.flip();

        // Test length 0
        byte[] pattern = new byte[0];
        assertEquals(0, buffer.indexOf(pattern));

        // Test length 1
        pattern = new byte[1];
        for (int i = 0; i < 10; i++) {
            random.nextBytes(pattern);
View Full Code Here


        // Test length 1
        pattern = new byte[1];
        for (int i = 0; i < 10; i++) {
            random.nextBytes(pattern);
            assertEquals((int) (pattern[0] & 0xff), buffer.indexOf(pattern));
        }

        // Test length n
        for (int i = 0; i < 10; i++) {
            int pos = random.nextInt(250);
View Full Code Here

            int pos = random.nextInt(250);
            pattern = new byte[5];
            for (int j = 0; j < pattern.length; j++) {
                pattern[j] = (byte) (pos + j);
            }
            assertEquals(pos, buffer.indexOf(pattern));
        }

        // Test wrong
        pattern = new byte[2];
        byte b = (byte) random.nextInt(256);
View Full Code Here

        // Test wrong
        pattern = new byte[2];
        byte b = (byte) random.nextInt(256);
        pattern[0] = b;
        pattern[1] = (byte) (b - 1);
        assertEquals(-1, buffer.indexOf(pattern));

        buffer.clear();
        int randomPosition = random.nextInt(buffer.capacity());
        buffer.position(randomPosition);
        buffer = buffer.slice();
View Full Code Here

        buffer.clear();
        int randomPosition = random.nextInt(buffer.capacity());
        buffer.position(randomPosition);
        buffer = buffer.slice();
        assertEquals(0, buffer.indexOf(new byte[] { (byte) randomPosition }));
    }

    public void testDuplicate() {
        Buffer buffer = newBuffer(random.nextInt(100) + 8);
        buffer.putInt(0);
View Full Code Here

    private static final byte[] TOKEN = "\r\n\r\n".getBytes();
    private static final Pattern PATTERN = Pattern.compile(" ");

    public Object decode(Session session, Packet packet) throws Exception {
        Buffer buffer = packet.getContent();
        int index = buffer.indexOf(TOKEN);
        if (index >= 0) {
            String[] headers = buffer.getString(Charset.UTF8,
                    index + TOKEN.length).split("\r\n");

            HttpRequest request = new HttpRequest();
View Full Code Here

     */
    private static class ChatMessageDecoder implements PacketDecoder {

        public Object decode(Session session, Packet packet) throws Exception {
            Buffer buffer = packet.getContent();
            int index = buffer.indexOf(TOKEN);
            if (index >= 0) {
                String s = buffer.getString(Charset.SYSTEM, index
                        - buffer.position());
                buffer.skip(TOKEN.length);
                return s;
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.