I\'m using a java jar to send and receive messages using Chrome Native Messaging.
I enabled logging of Chrome so I could read C:\\Users\\%UserName%\\AppData\\Local
I think you have to swap the order of the bytes defining your message length. Change your getBytes() method to this:
public byte[] getBytes(int length) {
byte[] bytes = new byte[4];
bytes[3] = (byte) (length & 0xFF);
bytes[2] = (byte) ((length >> 8) & 0xFF);
bytes[1] = (byte) ((length >> 16) & 0xFF);
bytes[0] = (byte) ((length >> 24) & 0xFF);
return bytes;
}