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 testWriteUtf8() {
        Assert.assertNull(BytesUtil.writeUtf8(null));

        Assert.assertArrayEquals(new byte[] { 102, 111, 111 }, BytesUtil.writeUtf8("foo"));
    }