I have an application that receives data in binary form through Bluetooth. I read the data using inputstream from a bluetoothsocket to a byte[]. But I must parse all messages, because they must have a given format to be valid. All messages are in binary.
My solution was to convert the byte[] to a string and then split the string and parse all received messages.
An example of the data to parse: 0000000010000001
I should know that the first 8 zeros are the header and 10000001 the real data.
My idea was to create a string (from the byte[]) that represents -> 0000000010000001 using new String(byte[]) and then split the whole string in one byte and check the value, like:
string1 had 00000000 string2 had 10000001
I know that 8 zeros are the header, therefore string2 has the representation of the data.
My question is about the efficiency of this method. Is this the best method to do this in a mobile environment?
new String(byte[])doesn't do "binary" 010101 strings, but interprets thebyte[]as characters using the default encoding (ASCII, UTF-8, etc.): download.oracle.com/javase/6/docs/api/java/lang/… (link here because parser doesn't like[]in markup)