What is best way to convert ByteMessage to String? I have the following code, do we have a more clean way?
BytesMessage byteMessage; // set byteMessage
byte[] byteArr = new byte[(int)byteMessage.getBodyLength()];
for (int i = 0; i < (int) byteMessage.getBodyLength(); i++) {
byteArr[i] = byteMessage.readByte();
}
String msg = new String(byteArr);
well, first it would probably be more efficient to call readBytes(byte[]).
second, you are converting the bytes to a String using the platform character encoding, which is always dangerous. you should be using an explicit charset. either one known to be specified for the message type, or possibly a charset included as a message property.