How to implement an unsigned byte in java, restriction being the size should be 1 byte only i.e. we cannot convert to short or int by And' ing with 0xFF
I have to transfer an unsigned byte array through the socket as recieving end is a C code method expecting an unsigned byte array of size 1 byte only, But since Java doesnt support the concept of unsigned byte the problem occurs. Do we have any means to achieve this.
byte b=(byte)0xF0; or even byte b1=0x00; is not properly send over socket channel. Please see the method for writting to the server.
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
//lProxylogger.info("Inside ProtocolEncoderAdapter. Encoding response to client..");
String response ;
//lProxylogger.info("The response length in encode adapter is "+ response.length()+" Message="+response);
byte[] responseStream;
response=(String) message;
responseStream= response.getBytes("windows-1252");
//responseStream=serialize(message);
IoBuffer buffer = IoBuffer.allocate(responseStream.length);
// buffer.putInt(response.length);
//IoBuffer buffer=(IoBuffer)message;
// buffer.putObject(message);
System.out.println("Encoded Response:"+new String(responseStream));
for(byte b:responseStream)
System.out.print(b+",");
System.out.println();
buffer.put(responseStream);
// lProxylogger.info("the response buffer size is "+ buffer.capacity());
buffer.setAutoShrink(true);
buffer.shrink();
// lProxylogger.info("After shrinking the buffer size is "+ buffer.capacity());
buffer.flip();
//System.out.println("Writing response to Stream..");
out.write(buffer);
}