2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package java.nio.charset;
20 * Provides convenient access to the most important built-in charsets. Saves a hash lookup and
21 * unnecessary handling of UnsupportedEncodingException at call sites, compared to using the
24 * Also various special-case charset conversions (for performance).
26 * @hide internal use only
28 public class Charsets {
30 * A cheap and type-safe constant for the ISO-8859-1 Charset.
32 public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
35 * A cheap and type-safe constant for the US-ASCII Charset.
37 public static final Charset US_ASCII = Charset.forName("US-ASCII");
40 * A cheap and type-safe constant for the UTF-8 Charset.
42 public static final Charset UTF_8 = Charset.forName("UTF-8");
45 * Returns a new byte array containing the bytes corresponding to the given characters,
46 * encoded in US-ASCII. Unrepresentable characters are replaced by (byte) '?'.
48 public static native byte[] toAsciiBytes(char[] chars, int offset, int length);
51 * Returns a new byte array containing the bytes corresponding to the given characters,
52 * encoded in ISO-8859-1. Unrepresentable characters are replaced by (byte) '?'.
54 public static native byte[] toIsoLatin1Bytes(char[] chars, int offset, int length);
57 * Returns a new byte array containing the bytes corresponding to the given characters,
58 * encoded in UTF-8. All characters are representable in UTF-8.
60 public static native byte[] toUtf8Bytes(char[] chars, int offset, int length);
63 * Decodes the given US-ASCII bytes into the given char[]. Equivalent to but faster than:
65 * for (int i = 0; i < count; ++i) {
66 * char ch = (char) (data[start++] & 0xff);
67 * value[i] = (ch <= 0x7f) ? ch : REPLACEMENT_CHAR;
70 public static native void asciiBytesToChars(byte[] bytes, int offset, int length, char[] chars);
73 * Decodes the given ISO-8859-1 bytes into the given char[]. Equivalent to but faster than:
75 * for (int i = 0; i < count; ++i) {
76 * value[i] = (char) (data[start++] & 0xff);
79 public static native void isoLatin1BytesToChars(byte[] bytes, int offset, int length, char[] chars);