E
Ed
All,
I have an annoying problem with ByteBuffer (BB).
I am reading from a telnet server - telnet sends bytes that can be any
hex value, some have special meaning to telnet.
I have the following code:
for (int i = 0; i < 255; i++)
{
ch = (char) i;
test = new StringBuffer();
test.append((char) i);
byteBuffer.put(test.toString().getBytes());
byteBuffer.flip();
back = byteBuffer.get();
// Uncomment below to see more working ...
/*
if (back < 0)
{
System.out.println("... adding 256 ....");
back = back + 256;
}
*/
backch = (char) back;
if (ch != backch)
{
System.out.println("ERROR - following do not match:");
}
System.out.println("" + i + " [" + ch + "] = " + back + " [" +
backch + "]");
byteBuffer.clear();
}
The code works ok up to value 127. From 129 to 159 (hex 80 to 9F)
bytebuffer always gives back the '?' char (int 63). From 160 to 255 I
get a negative number.
You will see the commented out code - adding that solves the problem
of 160 to 255 but I still get the 63 in the 129 to 159 range.
I am obviously doing something wrong.
Any help would be much appreciated.
regards
Ed
I have an annoying problem with ByteBuffer (BB).
I am reading from a telnet server - telnet sends bytes that can be any
hex value, some have special meaning to telnet.
I have the following code:
for (int i = 0; i < 255; i++)
{
ch = (char) i;
test = new StringBuffer();
test.append((char) i);
byteBuffer.put(test.toString().getBytes());
byteBuffer.flip();
back = byteBuffer.get();
// Uncomment below to see more working ...
/*
if (back < 0)
{
System.out.println("... adding 256 ....");
back = back + 256;
}
*/
backch = (char) back;
if (ch != backch)
{
System.out.println("ERROR - following do not match:");
}
System.out.println("" + i + " [" + ch + "] = " + back + " [" +
backch + "]");
byteBuffer.clear();
}
The code works ok up to value 127. From 129 to 159 (hex 80 to 9F)
bytebuffer always gives back the '?' char (int 63). From 160 to 255 I
get a negative number.
You will see the commented out code - adding that solves the problem
of 160 to 255 but I still get the 63 in the 129 to 159 range.
I am obviously doing something wrong.
Any help would be much appreciated.
regards
Ed