you could optimize this by check if ByteBuf.hasArray() and if so use the underlying array directly. This will save some memory copies.