Code example for ByteArrayOutputStream

Methods: reset, toByteArray

0
        assertEquals(testString, element.getText());
    } 
     
    public void testSerializeToBytes() throws Exception { 
        OMSourcedElement element = createSourcedElement("test", UTF8);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        element.serialize(baos);
        byte[] actual = baos.toByteArray();
        baos.reset();
        // We validate the result by creating an equivalent OMElement 
        // and calling serialize on it. The two results must be identical. 
        element.cloneOMElement().serialize(baos);
        byte[] expected = baos.toByteArray();
        assertTrue(Arrays.equals(expected, actual));
    } 
     
    public void testSerializeToChars() throws Exception { 
        OMSourcedElement element = createSourcedElement("test", UTF8);
        StringWriter sw = new StringWriter();
        element.serialize(sw);
        String actual = sw.toString();