Package java.nio.charset
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 voidasciiBytesToChars(byte[] bytes, int offset, int length, char[] chars)Decodes the given US-ASCII bytes into the given char[].static voidisoLatin1BytesToChars(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.
-
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); }
-