JInterface question

Olivier Sambourg <>
Wed Jun 15 18:33:42 CEST 2005


Hi again

I examined the data at byte level and here is what I found :

1> binary_to_list(term_to_binary("test")).
[131,107,0,4,116,101,115,116]

2> binary_to_list(term_to_binary(test)).
[131,100,0,4,116,101,115,116]

3> binary_to_list(term_to_binary({test, "test"})).
[131,104,2,100,0,4,116,101,115,116,107,0,4,116,101,115,116]

whereas :

OtpErlangString S = new OtpErlangString("test");
OtpOutputStream B = new OtpOutputStream(S);
B.toByteArray();
[107, 0, 4, 116, 101, 115, 116]

OtpErlangAtom S = new OtpErlangAtom("test");
OtpOutputStream B = new OtpOutputStream(S);
B.toByteArray();
[100, 0, 4, 116, 101, 115, 116]

OtpErlangObject O[] = {new OtpErlangAtom("test"), new 
OtpErlangString("test")};
OtpErlangTuple T = new OtpErlangTuple(O);
OtpOutputStream B = new OtpOutputStream(T);
B.toByteArray();
[104, 2, 100, 0, 4, 116, 101, 115, 116, 107, 0, 4, 116, 101, 115, 116]

It seems the only difference is the leading 131 byte in erlang. Can anyone 
confirm that it is always present ? If it is the case, I guess I have my 
solution.

Thanks again,

--
Olivier

2005/6/15, Olivier Sambourg <>:
> 
> Hi everyone
> 
> I'm trying to encapsulate erlang data inside an XMPP (jabber) stream and 
> retrieve the data with a java client.
> So on the server side it looks like this :
> 
> 1> httpd_util:encode_base64(binary_to_list(term_to_binary("test"))).
> "g2sABHRlc3Q="
> 
> And on the client side I've tried the following :
> OtpErlangString S = new OtpErlangString("test");
> OtpOutputStream B = new OtpOutputStream(B);
> Base64.encodeObject(B.toByteArray()); -> 
> "rO0ABXVyAAJbQqzzF/gGCFTgAgAAeHAAAAAHawAEdGVzdA=="
> Base64.encodeBytes(B.toByteArray()); -> "awAEdGVzdA=="
> Base64.encodeObject(B.toString()); -> 
> "rO0ABXQALmNvbS5lcmljc3Nvbi5vdHAuZXJsYW5nLk90cE91dHB1dFN0cmVhbUBmNjQzOGQ="
> 
> I've also tried to build an OtpErlangBinary from the OtpOutputStream, then 
> use the toString() method, to no avail...
> 
> (I'm using the Base64 java library from 
> http://iharder.sourceforge.net/base64/ but I guess the problem does not 
> come from this)
> 
> Do you have any suggestions to my problem ? I guess I'm just not using the 
> right transformation in Java to reproduce the 
> binary_to_list(term_to_binary()) operation...
> 
> Thank you
> 
> --
> Olivier
> 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20050615/25b40e33/attachment.html>


More information about the erlang-questions mailing list