Search in sources :

Example 1 with Base64EncodingStringBufferOutputStream

use of org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream in project webservices-axiom by apache.

the class TextContent method appendTo.

@Override
public void appendTo(StringBuilder buffer) {
    if (binary) {
        Base64EncodingStringBufferOutputStream out = new Base64EncodingStringBufferOutputStream(buffer);
        try {
            getDataHandler().writeTo(out);
            out.complete();
        } catch (IOException ex) {
            throw new OMException(ex);
        }
    } else {
        buffer.append(value);
    }
}
Also used : Base64EncodingStringBufferOutputStream(org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Example 2 with Base64EncodingStringBufferOutputStream

use of org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream in project webservices-axiom by apache.

the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementNonCoalescing.

private void testGetDataHandlerFromElementNonCoalescing(boolean useDHR) throws Exception {
    // We generate base64 that is sufficiently large to force the parser to generate
    // multiple CHARACTER events
    StringBuffer buffer = new StringBuffer("<test>");
    Base64EncodingStringBufferOutputStream out = new Base64EncodingStringBufferOutputStream(buffer);
    byte[] data = new byte[65536];
    new Random().nextBytes(data);
    out.write(data);
    out.complete();
    buffer.append("</test>");
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(StAXParserConfiguration.NON_COALESCING, new StringReader(buffer.toString()));
    if (useDHR) {
        reader = new XMLStreamReaderWithDataHandlerReader(reader);
    }
    try {
        reader.next();
        // Check precondition
        assertTrue(reader.isStartElement());
        DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);
        // Check postcondition
        assertTrue(reader.isEndElement());
        assertTrue(Arrays.equals(data, IOUtils.toByteArray(dh.getInputStream())));
    } finally {
        reader.close();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Random(java.util.Random) Base64EncodingStringBufferOutputStream(org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream) StringReader(java.io.StringReader) DataHandler(javax.activation.DataHandler)

Aggregations

Base64EncodingStringBufferOutputStream (org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Random (java.util.Random)1 DataHandler (javax.activation.DataHandler)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 OMException (org.apache.axiom.om.OMException)1