Satya
Satya

Reputation: 1249

How can I convert a string containing the binary data pattern into bytes using java?

I have to consume a web-service which is expecting a PDF file(base64binary data) as string. As the communication is done in XML UTF-8 encoding the string has many invalid elements, It is throwing a error. I tried with keeping the string CDATA but still its not working. Any idea how to overcome this situation?

I tried to write the binary data to string by formatting i.e 0x530x770x610x720x6F0x6F0x70 now how to get it back to bytes? can i read this pattern into bytes?

I am unsing Websphere process server and Websphere Integration Developer. We downloaded the chunck from a webservice and now need to send the base64binary as string to other service which we are struck. please help urget

Upvotes: 0

Views: 355

Answers (1)

themel
themel

Reputation: 8895

It looks like you're misunderstanding what you're supposed to do - you can't write binary data into a text stream (since, as you figured out already, not every binary sequence will consist of valid characters). This is why your spec says base64binary, not raw binary. Let me quote:

Definition:

base64Binary represents Base64-encoded arbitrary binary data. The ·value space· of base64Binary is the set of finite-length sequences of binary octets. For base64Binary data the entire binary stream is encoded using the Base64 Alphabet in [RFC 2045].

The lexical forms of base64Binary values are limited to the 65 characters of the Base64 Alphabet defined in [RFC 2045], i.e., a-z, A-Z, 0-9, the plus sign (+), the forward slash (/) and the equal sign (=), together with the characters defined in [XML 1.0 (Second Edition)] as white space. No other characters are allowed.

You're not telling us what system you're using, so I can't tell you precisely how to encode your data, but you'll find pre-existing implementations of base64 for pretty much every language.

Upvotes: 1

Related Questions