Originally posted by Paul Clapham:
You get an int that contains 255 when you read a certain byte from the array. Casting that int to byte gives you -1. This is perfectly normal because bytes contain numbers between -128 and +127. The bits are the same in any case.
Is the problem just that you see -1 where you expect to see 255, or is there a more practical problem?
(actually it's the 216 that gets converted to -1)
I'm not sure what you mean, but the changing of the bytes causes two problems:
1. Reading the data from the outputstream in a loop, causes it to terminate at the wrong point (since I have the loop doing the usual read = in.read() != -1).
2. The data, which is then written to disk, not only terminates before the end of the data but writes the wrong bytes to disk.
How do I fix this? What's causing this?
I understand what you're saying about converting byte to int, but ByteArrayInputStream.read() returns an int and it's "216", and ByteArrayOutputStream.write() takes an
int, the same thing! So why is there a conversion going on there? How do I stop it?