I think you're confusing byte arrays with their debug string representations. Byte arrays (or Buffers) do not necessarily contain UTF-8 text and do not make sense to print as text, and so when you try to print them out in various languages, the runtime will try to create a human-readable text representation of the value as a convenience. Java and Node do this in completely different ways for the same underlying values.
Java: The string [B@e3bbd6a
is not the content of a byte array. When you call toString()
on a Java byte[]
, you get some text like this, but all it's telling you is that the object is a byte array located at address e3bbd6a
. This is not the content of the array, it's just the memory address. (The idea here is that if you printed two different byte[]
values you would be able to tell if they are the same object based on the addresses matching, but otherwise the text is totally meaningless.)
Node: The string <Buffer 00 c0 a9 ...>
is again just a friendly human-readable string meant for debugging purposes. This isn't the actual low-level representation -- the low-level representation is raw bytes, i.e. the numeric values 00
, c0
, a9
, etc.
There is no need to "convert" between the two. If you have a byte[]
in Java and you write it to a socket or file, and then you read that socket or file in Node into a Buffer object, the Buffer will in fact contain the same data.