feat(新增): 🚀 netty的 ByteCompositeByteBuff
This commit is contained in:
parent
a616b10885
commit
c22915a471
|
@ -0,0 +1,24 @@
|
||||||
|
package cn.bunny.service.netty.demo3;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
|
import io.netty.buffer.CompositeByteBuf;
|
||||||
|
|
||||||
|
import static cn.bunny.service.NettyLogUtil.log;
|
||||||
|
|
||||||
|
public class ByteCompositeByteBuff {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ByteBuf buf1 = ByteBufAllocator.DEFAULT.buffer();
|
||||||
|
buf1.writeBytes(new byte[]{1, 2, 3, 4, 5});
|
||||||
|
|
||||||
|
ByteBuf buf2 = ByteBufAllocator.DEFAULT.buffer();
|
||||||
|
buf2.writeBytes(new byte[]{6, 7, 8, 9, 10});
|
||||||
|
|
||||||
|
// 将前两个字节拼接在一起
|
||||||
|
CompositeByteBuf buffer = ByteBufAllocator.DEFAULT.compositeBuffer();
|
||||||
|
buffer.addComponents(true, buf1, buf2);
|
||||||
|
|
||||||
|
log(buffer);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue