/**
* 在原byte数组前加上2位的长度字节
* @param b 原数组
* @return
*/
public static byte[] addLengthToByteArray(byte[] b) {
int length = b.length;
byte[] nameAndLength = new byte[length + 2];
System.arraycopy(Converser.short2Bytes((short) length), 0, nameAndLength, 0, 2);
System.arraycopy(b, 0, nameAndLength, 2, length);
return nameAndLength;
}
转载于:https://my.oschina.net/hongchq/blog/70271