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);
        }
    }
@Test
    public void toUtf8BytesTest() {
        for (int i = 0; i < 100000; i++) {
            String in = UUID.randomUUID().toString();
            assertArrayEquals(Utils.getBytes(in), BytesUtil.writeUtf8(in));
        }
    }