RSS Forums RSS

Include Base64 encoded data into XML

Please support our Java advertiser: Programming Forums
Thread Solved
Reply
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

  #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:

<xs:complexType name="MessagePart">
<xs:simpleContent>
<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"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

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,

Alessandro
AddThis Social Bookmark Button
Reply With Quote  
Posts: 7,398
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: 439
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

  #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.

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

-- Eric Naggum RIP :-(
Reply With Quote  
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

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

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

Alessandro
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Java Forum
Views: 940 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:33 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC