I read from a TCP/IP socket s:
byte[] bbuf = new byte[30];
s.getInputStream().read(bbuf);
for (int i = 0; i < bbuf.length; i++)
{
System.out.println(Integer.toHexString( (int) (bbuf[i] & 0xff)));
}
This outputs CA 68 9F 75 which is what I would expect. Now I want to use chars instead
char[] cbuf = new char[30];
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
for (int i = 0; i < cbuf.length; i++)
{
System.out.println(Integer.toHexString( (int) (cbuf[i] )));
}
Now the output is CA 68 178 75. So the third Byte (and only the third byte) makes the difference. I assume it has to do with the character sets and that I have to specify a character set in the InputStreamer. I have no idea how to find out what character set I have to use. Secondly I am surprised if it is due to character sets that I only get the mess with exactly one character. I tried all kind of other characters but that seems to be the only one I was able to find.
Who can solve the mystery?