Your answer is nearly in your question. If you )]wrap a byte array from the server in a ByteBuffer and set the correct byte order, you can get integers, characters and other types from arbitrary offsets in the buffer.
Unless the InputStreamReader is using the ISO-8859-1 encoding, there may not be enough information left in the character array to get the binary data back out. For example, the integer 1000, in little endian order, is the bytes [-24, 3, 0, 0]. If you convert that to characters encoded as UTF-8 via an InputStreamReader, then back via a String, you get [-17, -65, -67, 3, 0, 0].
Without knowing any more about your protocol, I think you will need to switch to reading to a byte array (or ByteBuffer) to read the 4-byte integers correctly.
Is the server sending the data in Unicode characters? Or is your read method converting the original input to characters? InputStreamReader is a bridge from byte streams to character streams. What is the format for the data coming from the server? Maybe you need to tailor your read routine to read the data in the same format it is sent in. [ July 30, 2008: Message edited by: Norm Radder ]
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop