@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { try { ByteBuf recvBuf = Unpooled.copiedBuffer((ByteBuf) msg); byte[] buf = new byte[recvBuf.capacity()]; recvBuf.readBytes(buf); String request = new String(buf, CharsetUtil.UTF_8); System.out.println("받는 Data : " + request); broadCast(ctx, request); } finally { ReferenceCountUtil.release(msg); } }
@Override public int readBytes(GatheringByteChannel out, int length) throws IOException { return buf.readBytes(out, length); }
@Override public ByteBuf readBytes(OutputStream out, int length) throws IOException { buf.readBytes(out, length); return this; }
@Override public ByteBuf readBytes(ByteBuffer dst) { buf.readBytes(dst); return this; }
@Override public ByteBuf readBytes(byte[] dst, int dstIndex, int length) { buf.readBytes(dst, dstIndex, length); return this; }
@Override public ByteBuf readBytes(byte[] dst) { buf.readBytes(dst); return this; }
@Override public ByteBuf readBytes(ByteBuf dst, int length) { buf.readBytes(dst, length); return this; }
@Override public ByteBuf readBytes(int length) { return buf.readBytes(length); }
@Test public void testEmptyBuffer() { ByteBuf b = freeLater(wrappedBuffer(new byte[] {1, 2}, new byte[] {3, 4})); b.readBytes(new byte[4]); b.readBytes(EMPTY_BYTES); }