Class StringUtf8Utils


  • @Internal
    public final class StringUtf8Utils
    extends Object
    Utilities for String UTF-8.
    • Method Detail

      • encodeUTF8

        public static byte[] encodeUTF8​(String str)
        This method must have the same result with JDK's String.getBytes.
      • encodeUTF8

        public static int encodeUTF8​(String str,
                                     byte[] bytes)
      • defaultEncodeUTF8

        public static int defaultEncodeUTF8​(String str,
                                            byte[] bytes)
      • decodeUTF8

        public static String decodeUTF8​(byte[] input,
                                        int offset,
                                        int byteLen)
      • decodeUTF8Strict

        public static int decodeUTF8Strict​(byte[] sa,
                                           int sp,
                                           int len,
                                           char[] da)
      • defaultDecodeUTF8

        public static String defaultDecodeUTF8​(byte[] bytes,
                                               int offset,
                                               int len)
      • allocateReuseBytes

        public static byte[] allocateReuseBytes​(int length)
        Allocate bytes that is only for temporary usage, it should not be stored in somewhere else. Use a ThreadLocal to reuse bytes to avoid overhead of byte[] new and gc.

        If there are methods that can only accept a byte[], instead of a MemorySegment[] parameter, we can allocate a reuse bytes and copy the MemorySegment data to byte[], then call the method. Such as String deserialization.

      • allocateReuseChars

        public static char[] allocateReuseChars​(int length)