Class Utf8

  • Direct Known Subclasses:
    Utf8Safe

    public abstract class Utf8
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Utf8()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.lang.String decodeUtf8​(java.nio.ByteBuffer buffer, int offset, int length)
      Decodes the given UTF-8 portion of the ByteBuffer into a String.
      abstract int encodedLength​(java.lang.CharSequence sequence)
      Returns the number of bytes in the UTF-8-encoded form of sequence.
      abstract void encodeUtf8​(java.lang.CharSequence in, java.nio.ByteBuffer out)
      Encodes the given characters to the target ByteBuffer using UTF-8 encoding.
      static Utf8 getDefault()
      Get the default UTF-8 processor.
      static void setDefault​(Utf8 instance)
      Set the default instance of the UTF-8 processor.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utf8

        public Utf8()
    • Method Detail

      • encodedLength

        public abstract int encodedLength​(java.lang.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:
        java.lang.IllegalArgumentException - if sequence contains ill-formed UTF-16 (unpaired surrogates)
      • encodeUtf8

        public abstract void encodeUtf8​(java.lang.CharSequence in,
                                        java.nio.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.
      • decodeUtf8

        public abstract java.lang.String decodeUtf8​(java.nio.ByteBuffer buffer,
                                                    int offset,
                                                    int length)
        Decodes the given UTF-8 portion of the ByteBuffer into a String.
        Throws:
        java.lang.IllegalArgumentException - if the input is not valid UTF-8.
      • 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