I have to base64 encode a large quantity of data and include it in the XML response of the webservice.The WSDL define the XML element in the following way:

<xs:complexType name="MessagePart">
<xs:extension base="xs:base64Binary">
<xs:attribute name="contentType" type="xs:string" default="text/plain" use="optional"/>
<xs:attribute name="length" type="xs:int" default="0" use="optional"/>
<xs:attribute name="offset" type="xs:int" default="0" use="optional"/>

I have implemented it but I have some doubts. I'm not sure it's the better way for doing it.

import org.apache.commons.codec.binary.Base64;

OMElement part = factory.createOMElement("part", emptyNs);
part.addAttribute("length", this.attachment.getLength(), null);
byte[] value = Base64.encodeBase64(this.attachment.getValue());
part.setText( new String(value) );

What about performance if I have an attachment of 1MB? I'm specially worried about the "new String()" operation.
Any suggestion will be appreciated. Thanks,