Examples of CharArrayBuffer


Examples of org.apache.http.util.CharArrayBuffer

        assertEquals(4, buffer.indexOf(':', 0, 1000));
        assertEquals(-1, buffer.indexOf(':', 2, 1));
    }
   
    public void testSubstring() {
        CharArrayBuffer buffer = new CharArrayBuffer(16);
        buffer.append(" name:  value    ");
        assertEquals(5, buffer.indexOf(':'));
        assertEquals(" name", buffer.substring(0, 5));
        assertEquals("  value    ", buffer.substring(6, buffer.length()));
        assertEquals("name", buffer.substringTrimmed(0, 5));
        assertEquals("value", buffer.substringTrimmed(6, buffer.length()));
        assertEquals("", buffer.substringTrimmed(13, buffer.length()));
    }
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        assertEquals("value", buffer.substringTrimmed(6, buffer.length()));
        assertEquals("", buffer.substringTrimmed(13, buffer.length()));
    }
   
    public void testSubstringIndexOfOutBound() {
        CharArrayBuffer buffer = new CharArrayBuffer(16);
        buffer.append("stuff");
        try {
            buffer.substring(-2, 10);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.substringTrimmed(-2, 10);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.substring(12, 10);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.substringTrimmed(12, 10);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.substring(2, 1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.substringTrimmed(2, 1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
    }   
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        String s1 = "stuff";
        String s2 = " and more stuff";
        byte[] b1 = s1.getBytes("US-ASCII");
        byte[] b2 = s2.getBytes("US-ASCII");
       
        CharArrayBuffer buffer = new CharArrayBuffer(8);
        buffer.append(b1, 0, b1.length);
        buffer.append(b2, 0, b2.length);
       
        assertEquals("stuff and more stuff", buffer.toString());
    }
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

    }
   
    public void testAppendISOByteArray() throws Exception {
        byte[] b = new byte[] {0x00, 0x20, 0x7F, -0x80, -0x01};
       
        CharArrayBuffer buffer = new CharArrayBuffer(8);
        buffer.append(b, 0, b.length);
        char[] ch = buffer.toCharArray();
        assertNotNull(ch);
        assertEquals(5, ch.length);
        assertEquals(0x00, ch[0]);
        assertEquals(0x20, ch[1]);
        assertEquals(0x7F, ch[2]);
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        assertEquals(0x80, ch[3]);
        assertEquals(0xFF, ch[4]);
    }
   
    public void testAppendNullByteArray() throws Exception {
        CharArrayBuffer buffer = new CharArrayBuffer(8);
        buffer.append((byte[])null, 0, 0);
        assertEquals("", buffer.toString());
    }
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        buffer.append((byte[])null, 0, 0);
        assertEquals("", buffer.toString());
    }

    public void testAppendNullByteArrayBuffer() throws Exception {
        CharArrayBuffer buffer = new CharArrayBuffer(8);
        buffer.append((ByteArrayBuffer)null, 0, 0);
        assertEquals("", buffer.toString());
    }
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        buffer.append((ByteArrayBuffer)null, 0, 0);
        assertEquals("", buffer.toString());
    }

    public void testInvalidAppendAsciiByteArray() throws Exception {
        CharArrayBuffer buffer = new CharArrayBuffer(4);
        buffer.append((byte[])null, 0, 0);

        byte[] tmp = new byte[] { '1', '2', '3', '4'};
        try {
            buffer.append(tmp, -1, 0);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.append(tmp, 0, -1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.append(tmp, 0, 8);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.append(tmp, 10, Integer.MAX_VALUE);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.append(tmp, 2, 4);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
    }
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

    }

    public void testHttpVersionParsingUsingCursor() throws Exception {

        String s = "HTTP/1.1";
        CharArrayBuffer buffer = new CharArrayBuffer(16);
        buffer.append(s);
        ParserCursor cursor = new ParserCursor(0, s.length());
       
        LineParser parser = BasicLineParser.DEFAULT;
       
        HttpVersion version = (HttpVersion) parser.parseProtocolVersion(buffer, cursor);
        assertEquals("HTTP protocol name", "HTTP", version.getProtocol());
        assertEquals("HTTP major version number", 1, version.getMajor());
        assertEquals("HTTP minor version number", 1, version.getMinor());
        assertEquals("HTTP version number", "HTTP/1.1", version.toString());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());
       
        s = "HTTP/1.123 123";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        version = (HttpVersion) parser.parseProtocolVersion(buffer, cursor);
        assertEquals("HTTP protocol name", "HTTP", version.getProtocol());
        assertEquals("HTTP major version number", 1, version.getMajor());
        assertEquals("HTTP minor version number", 123, version.getMinor());
        assertEquals("HTTP version number", "HTTP/1.123", version.toString());
        assertEquals(' ', buffer.charAt(cursor.getPos()));
        assertEquals(s.length() - 4, cursor.getPos());
        assertFalse(cursor.atEnd());
    }
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        buffer.append("and stuff like that");
        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        SessionOutputBufferMockup outbuffer = new SessionOutputBufferMockup();
        for (int i = 0; i < teststrs.length; i++) {
            chbuffer.clear();
            chbuffer.append(teststrs[i]);
            outbuffer.writeLine(chbuffer);
        }
        //these write operations should have no effect
        outbuffer.writeLine((String)null);
        outbuffer.writeLine((CharArrayBuffer)null);
View Full Code Here

Examples of org.apache.http.util.CharArrayBuffer

        buffer.append("and stuff like that");
        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        SessionOutputBufferMockup outbuffer = new SessionOutputBufferMockup();
        for (int i = 0; i < teststrs.length; i++) {
            chbuffer.clear();
            chbuffer.append(teststrs[i]);
            outbuffer.writeLine(chbuffer);
        }
        //these write operations should have no effect
        outbuffer.writeLine((String)null);
        outbuffer.writeLine((CharArrayBuffer)null);
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.