Include Base64 encoded data into XML

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2008
Posts: 2
Reputation: afolli is an unknown quantity at this point 
Solved Threads: 0
afolli afolli is offline Offline
Newbie Poster

Include Base64 encoded data into XML

 
0
  #1
Sep 11th, 2008
Hello,
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:

  1. <xs:complexType name="MessagePart">
  2. <xs:simpleContent>
  3. <xs:extension base="xs:base64Binary">
  4. <xs:attribute name="contentType" type="xs:string" default="text/plain" use="optional"/>
  5. <xs:attribute name="length" type="xs:int" default="0" use="optional"/>
  6. <xs:attribute name="offset" type="xs:int" default="0" use="optional"/>
  7. </xs:extension>
  8. </xs:simpleContent>
  9. </xs:complexType>

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


  1. import org.apache.commons.codec.binary.Base64;
  2. ...
  3.  
  4. OMElement part = factory.createOMElement("part", emptyNs);
  5. part.addAttribute("length", this.attachment.getLength(), null);
  6. byte[] value = Base64.encodeBase64(this.attachment.getValue());
  7. 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,

Alessandro
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,652
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Include Base64 encoded data into XML

 
0
  #2
Sep 12th, 2008
Why are you encoding textual data? Base64 is primarily meant to encode binary data.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: afolli is an unknown quantity at this point 
Solved Threads: 0
afolli afolli is offline Offline
Newbie Poster

Re: Include Base64 encoded data into XML

 
0
  #3
Sep 16th, 2008
In fact I'm encoding binary data. Actually, I have changed it in the following way.

  1. import com.sun.xml.rpc.encoding.simpletype.XSDBase64BinaryEncoder;
  2. ...
  3. OMElement part = factory.createOMElement("part", emptyNs);
  4. part.addAttribute("length", "" + this.attachment.getLength() + "",null);
  5. part.setText(XSDBase64BinaryEncoder.getInstance().objectToString( this.attachment.get_value() , null ));

Alessandro
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1274 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC