How can I pass array byte to getReader without changes data.
byte_msg = Some array byte
println(">>>" + byte_msg)
HttpServletRequest.getReader returns new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(byte_msg)))
And post reciever:
byte_msg = IOUtils.toByteArray(post.request.getReader)
println("<<<" + byte_msg)
And print return. Why do I get different answers?
>>>[B@38ffd135
<<<[B@60c0c8b5
You’re printing out the result of
byte[].toString()– which isn’t the value of the byte array… it’s just the value returned byObject.toString()–[Bfor “byte array”,@and then the hash code. You need to convert the data to hex or something like that – which you need to do explicitly. For example, you could use theHexclass from Apache Commons Codec:Not that if this is arbitrary binary data you should not use
InputStreamReaderto convert it to a string in the first place.InputStreamReaderis designed for binary data which is encoded text data – and IMO you should specify the encoding, too.If you want to transfer arbitrary binary data, you should either transfer it without any conversion into text (so see whether your post class allows that) or use something like hex or base64 to convert to/from binary data safely.