Class Utf8

    • Constructor Detail

      • Utf8

        public Utf8()
    • Method Detail

      • encodedLength

        public abstract int encodedLength​(CharSequence sequence)
        Returns the number of bytes in the UTF-8-encoded form of sequence. For a string, this method is equivalent to string.getBytes(UTF_8).length, but is more efficient in both time and space.
        Throws:
        IllegalArgumentException - if sequence contains ill-formed UTF-16 (unpaired surrogates)
      • encodeUtf8

        public abstract void encodeUtf8​(CharSequence in,
                                        ByteBuffer out)
        Encodes the given characters to the target ByteBuffer using UTF-8 encoding.

        Selects an optimal algorithm based on the type of ByteBuffer (i.e. heap or direct) and the capabilities of the platform.

        Parameters:
        in - the source string to be encoded
        out - the target buffer to receive the encoded string.
      • getDefault

        public static Utf8 getDefault()
        Get the default UTF-8 processor.
        Returns:
        the default processor
      • setDefault

        public static void setDefault​(Utf8 instance)
        Set the default instance of the UTF-8 processor.
        Parameters:
        instance - the new instance to use
      • encodeUtf8CodePoint

        public static int encodeUtf8CodePoint​(CharSequence in,
                                              int start,
                                              byte[] out)
        Encode a Java's CharSequence UTF8 codepoint into a byte array.
        Parameters:
        in - CharSequence to be encoded
        start - start position of the first char in the codepoint
        out - byte array of 4 bytes to be filled
        Returns:
        return the amount of bytes occupied by the codepoint