public static UnsafeBuffer fromUtf8String()

in gflog-core/src/main/java/com/epam/deltix/gflog/core/util/Util.java [285:305]


    public static UnsafeBuffer fromUtf8String(final String string, int limit) {
        final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);

        if (bytes.length <= limit) {
            return new UnsafeBuffer(bytes);
        }

        byte b = bytes[limit];

        if ((b & 0b11000000) == 0b10000000) {
            while (limit > 0) {
                b = bytes[--limit];

                if ((b & 0b01000000) != 0) {
                    break;
                }
            }
        }

        return new UnsafeBuffer(bytes, 0, limit);
    }