java - Unable to get full length message -


i have implemented logic message byte array.

public getinfo(byte[] hi) {          type = ....          sequence = ....          int ack = ....          int lastbyte = ....;          int isutf8byte = .....;          actual_msg += (char) hi[char1];         actual_msg += (char) hi[char2];         actual_msg += (char) hi[char3];         actual_msg += (char) hi[char4];         actual_msg += (char) hi[char5];     } 

the problem gives me first 5 characters of message. mean if byte array contains hello how you, output hello. byte array has 3rd 7th byte(5 bytes) char messages.

i think logic remaining chars in message should inside for loop because have logic read first 5 chars. 0th 2nd byte same sets of messages. 3rs 7th byte of concern.

how can implement this?

if understanding question correctly, want

public string getmessage(byte[] bytes) {     stringbuilder message = new stringbuilder();      int index = 0     while (index < bytes.length) {         byte[] partofmessage = arrays.copyofrange(bytes, index + 3, index + 7);         message.append(new string(partofmessage , standardcharsets.utf_8));         index += 7;     }     return message.tostring(); } 

Comments