public static byte[] writeUtf8(final String in) {
        if (in == null) {
            return null;
        }
        if (UnsafeUtil.hasUnsafe()) {
            // Calculate the encoded length.
            final int len = UnsafeUtf8Util.encodedLength(in);
            final byte[] outBytes = new byte[len];
            UnsafeUtf8Util.encodeUtf8(in, outBytes, 0, len);
            return outBytes;
        } else {
            return in.getBytes(StandardCharsets.UTF_8);
        }
    }
This method has better performance than String#getBytes(Charset),
See the benchmark class: Utf8Benchmark for details.
jraft-core/src/main/java/com/alipay/sofa/jraft/util/BytesUtil.java