Change the use of ByteBuf.capacity() to ByteBuf.readBytes();