Package org.jf.util

Class Utf8Utils


  • public final class Utf8Utils
    extends java.lang.Object
    Constants of type CONSTANT_Utf8_info.
    • Constructor Summary

      Constructors 
      Constructor Description
      Utf8Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] stringToUtf8Bytes​(java.lang.String string)
      Converts a string into its Java-style UTF-8 form.
      static java.lang.String utf8BytesToString​(byte[] bytes, int start, int length)
      Converts an array of UTF-8 bytes into a string.
      static java.lang.String utf8BytesWithUtf16LengthToString​(byte[] bytes, int start, int utf16Length)
      Converts an array of UTF-8 bytes into a string.
      static java.lang.String utf8BytesWithUtf16LengthToString​(byte[] bytes, int start, int utf16Length, int[] readLength)
      Converts an array of UTF-8 bytes into a string.
      • Methods inherited from class java.lang.Object

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

      • Utf8Utils

        public Utf8Utils()
    • Method Detail

      • stringToUtf8Bytes

        public static byte[] stringToUtf8Bytes​(java.lang.String string)
        Converts a string into its Java-style UTF-8 form. Java-style UTF-8 differs from normal UTF-8 in the handling of character '\0' and surrogate pairs.
        Parameters:
        string - non-null; the string to convert
        Returns:
        non-null; the UTF-8 bytes for it
      • utf8BytesToString

        public static java.lang.String utf8BytesToString​(byte[] bytes,
                                                         int start,
                                                         int length)
        Converts an array of UTF-8 bytes into a string.
        Parameters:
        bytes - non-null; the bytes to convert
        start - the start index of the utf8 string to convert
        length - the length of the utf8 string to convert, not including any null-terminator that might be present
        Returns:
        non-null; the converted string
      • utf8BytesWithUtf16LengthToString

        public static java.lang.String utf8BytesWithUtf16LengthToString​(@Nonnull
                                                                        byte[] bytes,
                                                                        int start,
                                                                        int utf16Length)
        Converts an array of UTF-8 bytes into a string.
        Parameters:
        bytes - non-null; the bytes to convert
        start - the start index of the utf8 string to convert
        utf16Length - the number of utf16 characters in the string to decode
        Returns:
        non-null; the converted string
      • utf8BytesWithUtf16LengthToString

        public static java.lang.String utf8BytesWithUtf16LengthToString​(@Nonnull
                                                                        byte[] bytes,
                                                                        int start,
                                                                        int utf16Length,
                                                                        @Nullable
                                                                        int[] readLength)
        Converts an array of UTF-8 bytes into a string.
        Parameters:
        bytes - non-null; the bytes to convert
        start - the start index of the utf8 string to convert
        utf16Length - the number of utf16 characters in the string to decode
        readLength - If non-null, the first element will contain the number of bytes read after the method exits
        Returns:
        non-null; the converted string