Class Charsets

java.lang.Object
java.nio.charset.Charsets

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

    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​(char[] chars, int offset, int length)
    Returns a new byte array containing the bytes corresponding to the given characters, encoded in US-ASCII.
    static byte[] toBigEndianUtf16Bytes​(char[] chars, int offset, int length)
    Returns a new byte array containing the bytes corresponding to the given characters, encoded in UTF-16BE.
    static byte[] toIsoLatin1Bytes​(char[] chars, int offset, int length)
    Returns a new byte array containing the bytes corresponding to the given characters, encoded in ISO-8859-1.
    static byte[] toUtf8Bytes​(char[] chars, int offset, int length)
    Returns a new byte array containing the bytes corresponding to the given characters, encoded in UTF-8.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toAsciiBytes

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

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

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

      public static byte[] toBigEndianUtf16Bytes​(char[] chars, int offset, int length)
      Returns a new byte array containing the bytes corresponding to the given characters, 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); }