多个数组进行拼接,
1, 使用java自己的 System#arrayCopy()
byte[] message = new byte[heads.length + result.length + bodies.length]; System.arraycopy(heads, 0, message, 0, heads.length); System.arraycopy(result, 0, message, heads.length, result.length); System.arraycopy(bodies, 0, message, heads.length + result.length, bodies.length);
第二种方式, 使用netty的byteBuf
ByteBuf buffer = Unpooled.buffer(); buffer.writeBytes(heads); buffer.writeBytes(result); buffer.writeBytes(bodies); byte[] message1 = new byte[buffer.readableBytes()]; buffer.readBytes(message1);
未完待续...
原文地址:https://www.cnblogs.com/wenbronk/p/9144314.html
时间: 2024-10-04 04:45:59