Package libcore.util

Class CharsetUtils


  • public final class CharsetUtils
    extends Object
    Various special-case charset conversions (for performance).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void asciiBytesToChars​(byte[] bytes, int offset, int length, char[] chars)
      Decodes the given US-ASCII bytes into the given char[].
      static void isoLatin1BytesToChars​(byte[] bytes, int offset, int length, char[] chars)
      Decodes the given ISO-8859-1 bytes into the given char[].
      static byte[] toAsciiBytes​(String s, int offset, int length)
      Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in US-ASCII.
      static byte[] toBigEndianUtf16Bytes​(String s, int offset, int length)
      Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in UTF-16BE.
      static byte[] toIsoLatin1Bytes​(String s, int offset, int length)
      Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in ISO-8859-1.
      static byte[] toUtf8Bytes​(String s, int offset, int length)
      Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in UTF-8.
    • Method Detail

      • toAsciiBytes

        public static byte[] toAsciiBytes​(String s,
                                          int offset,
                                          int length)
        Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in US-ASCII. Unrepresentable characters are replaced by (byte) '?'.
      • toIsoLatin1Bytes

        public static byte[] toIsoLatin1Bytes​(String s,
                                              int offset,
                                              int length)
        Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in ISO-8859-1. Unrepresentable characters are replaced by (byte) '?'.
      • toUtf8Bytes

        public static byte[] toUtf8Bytes​(String s,
                                         int offset,
                                         int length)
        Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in UTF-8. All characters are representable in UTF-8.
      • toBigEndianUtf16Bytes

        public static byte[] toBigEndianUtf16Bytes​(String s,
                                                   int offset,
                                                   int length)
        Returns a new byte array containing the bytes corresponding to the characters in the given string, encoded in UTF-16BE. All characters are representable in UTF-16BE.
      • asciiBytesToChars

        public static void asciiBytesToChars​(byte[] bytes,
                                             int offset,
                                             int length,
                                             char[] chars)
        Decodes the given US-ASCII bytes into the given char[]. Equivalent to but faster than: for (int i = 0; i < count; ++i) { char ch = (char) (data[start++] & 0xff); value[i] = (ch <= 0x7f) ? ch : REPLACEMENT_CHAR; }
      • isoLatin1BytesToChars

        public static void isoLatin1BytesToChars​(byte[] bytes,
                                                 int offset,
                                                 int length,
                                                 char[] chars)
        Decodes the given ISO-8859-1 bytes into the given char[]. Equivalent to but faster than: for (int i = 0; i < count; ++i) { value[i] = (char) (data[start++] & 0xff); }