Code example for CharArrayBuffer

Methods: append, indexOf, length, substringTrimmed

0
            //expected 
        } 
    } 
 
    public void testHeaderElements() { 
        CharArrayBuffer buf = new CharArrayBuffer(32);
        buf.append("name: element1 = value1, element2; param1 = value1, element3");
        BufferedHeader header = new BufferedHeader(buf);
        HeaderElement[] elements = header.getElements();
        assertNotNull(elements);
        assertEquals(3, elements.length);
        assertEquals("element1", elements[0].getName());
        assertEquals("value1", elements[0].getValue());
        assertEquals("element2", elements[1].getName());
        assertEquals(null, elements[1].getValue());
        assertEquals("element3", elements[2].getName());
        assertEquals(null, elements[2].getValue());
        assertEquals(1, elements[1].getParameters().length);
    } 
 
    public void testCloning() throws Exception { 
        CharArrayBuffer buf = new CharArrayBuffer(32);
        buf.append("name: value");
        BufferedHeader orig = new BufferedHeader(buf);
        BufferedHeader clone = (BufferedHeader) orig.clone();
        assertEquals(orig.getName(), clone.getName());
        assertEquals(orig.getValue(), clone.getValue());
    } 
 
    public void testSerialization() throws Exception { 
        CharArrayBuffer buf = new CharArrayBuffer(32);
        buf.append("name: value");
        BufferedHeader orig = new BufferedHeader(buf);
        ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
        ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
        outstream.writeObject(orig);
        outstream.close();
        byte[] raw = outbuffer.toByteArray();
        ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
        ObjectInputStream instream = new ObjectInputStream(inbuffer);
        BufferedHeader clone = (BufferedHeader) instream.readObject();
        assertEquals(orig.getName(), clone.getName());
        assertEquals(orig.getValue(), clone.getValue());
    } 
 
}