Note regarding UTF-8. The JVMS defines its own version of the UTF-8 format so that it contains no zero bytes (modified UTF-8). This is not actually the same as Charset.forName("UTF-8").
See also:
The methods here support modified UTF-8.This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | Convert.
Modified UTF-8 decoding validation levels. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static int | chars2utf(char[]
The array holding the characters to convert. src, int The start index from which characters are converted. sindex, byte[] The array holding the converted characters.. dst, int The start index from which converted bytes
are written. dindex, int The maximum number of characters to convert. len)Copy characters in source array to bytes in target array, converting them to Utf8 representation. |
| public static byte[] | chars2utf(char[]
The array holding the characters. src, int The start index from which characters are converted. sindex, int The maximum number of characters to convert. len)Return characters as an array of bytes in Utf8 representation. |
| public static byte[] | chars2utf(char[]
The array holding the characters. src)Return all characters in given array as an array of bytes in Utf8 representation. |
| public static List | |
| public static List | |
| public static String | |
| private static boolean | |
| public static Name | packagePart(Name classname)
Return the package name of a class name, excluding the trailing '.', "" if not existent. |
| public static String | |
| public static String | |
| public static String | quote(char ch, boolean charContext)
Escapes a character if it has an escape sequence or is non-printable ASCII. |
| public static Name | |
| public static String | |
| public static int | |
| public static long | |
| public static byte[] | |
| public static int | Returns: the index indst just after the last copied charThe array holding the bytes to convert. src, int The start index from which bytes are converted. soff, char[] The array holding the converted characters,
or null to just validate dst, int The start index from which converted characters
are written. doff, int The maximum number of bytes to convert. len, Convert.Level of validation validationDecode characters encoded in Modified UTF-8 encoding using the given validation level. |
| public static char[] | Returns: The decoded characters in an array.The array holding the bytes. src, int The start index from which bytes are converted. sindex, int The maximum number of bytes to convert. len, Convert.Level of validation validationDecode characters encoded in Modified UTF-8 encoding. |
| public static String | utf2string(byte[]
The array holding the bytes. src, int The start index from which bytes are converted. sindex, int The maximum number of bytes to convert. len, Convert.Level of validation validationDecode a |
| public static int | Returns: the number of encoded charactersdata buffer buf, int starting offset of UTF-8 data off, int number of bytes of UTF-8 data len)Count the number of characters encoded in a Modified UTF-8 encoding. |
| public static void | utfValidate(byte[]
Buffer containing data buf, int Data starting offset off, int Data length len, Convert.Level of validation validationValidate the given Modified UTF-8 encoding using the given validation level. |
| Convert | back to summary |
|---|---|
| public Convert() | |
| chars2utf | back to summary |
|---|---|
| public static int chars2utf(char[] src, int sindex, byte[] dst, int dindex, int len) Copy characters in source array to bytes in target array, converting them to Utf8 representation. The target array must be large enough to hold the result. returns first index in `dst' past the last copied byte.
| |
| chars2utf | back to summary |
|---|---|
| public static byte[] chars2utf(char[] src, int sindex, int len) Return characters as an array of bytes in Utf8 representation.
| |
| chars2utf | back to summary |
|---|---|
| public static byte[] chars2utf(char[] src) Return all characters in given array as an array of bytes in Utf8 representation.
| |
| classCandidates | back to summary |
|---|---|
| public static List | |
| enclosingCandidates | back to summary |
|---|---|
| public static List | |
| escapeUnicode | back to summary |
|---|---|
| public static String escapeUnicode(String s) Escape all unicode characters in string. | |
| isPrintableAscii | back to summary |
|---|---|
| private static boolean isPrintableAscii(char ch) Is a character printable ASCII? | |
| packagePart | back to summary |
|---|---|
| public static Name packagePart(Name classname) Return the package name of a class name, excluding the trailing '.', "" if not existent. | |
| packagePart | back to summary |
|---|---|
| public static String packagePart(String classname) | |
| quote | back to summary |
|---|---|
| public static String quote(String s) Escapes each character in a string that has an escape sequence or is non-printable ASCII. Leaves non-ASCII characters alone. | |
| quote | back to summary |
|---|---|
| public static String quote(char ch, boolean charContext) Escapes a character if it has an escape sequence or is non-printable ASCII. Leaves non-ASCII characters alone. | |
| shortName | back to summary |
|---|---|
| public static Name shortName(Name name) Return the last part of a qualified name. | |
| shortName | back to summary |
|---|---|
| public static String shortName(String name) Return the last part of a qualified name from its string representation | |
| string2int | back to summary |
|---|---|
| public static int string2int(String s, int radix) throws NumberFormatException Convert string to integer. | |
| string2long | back to summary |
|---|---|
| public static long string2long(String s, int radix) throws NumberFormatException Convert string to long integer. | |
| string2utf | back to summary |
|---|---|
| public static byte[] string2utf(String s) Return string as an array of bytes in in Utf8 representation. | |
| utf2chars | back to summary |
|---|---|
| public static int utf2chars(byte[] src, int soff, char[] dst, int doff, int len, Convert. Decode characters encoded in Modified UTF-8 encoding using the given validation level.
Reject any invalid data by throwing an
| |
| utf2chars | back to summary |
|---|---|
| public static char[] utf2chars(byte[] src, int sindex, int len, Convert. Decode characters encoded in Modified UTF-8 encoding.
| |
| utf2string | back to summary |
|---|---|
| public static String utf2string(byte[] src, int sindex, int len, Convert. Decode a
| |
| utfNumChars | back to summary |
|---|---|
| public static int utfNumChars(byte[] buf, int off, int len) Count the number of characters encoded in a Modified UTF-8 encoding. This method does not check for invalid data.
| |
| utfValidate | back to summary |
|---|---|
| public static void utfValidate(byte[] buf, int off, int len, Convert. Validate the given Modified UTF-8 encoding using the given validation level.
Reject invalid data by throwing an Note there is no point in calling this method with
| |
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private final boolean | |
| private final boolean | |
| public static final Convert. | NONE
Do zero validation of UTF-8, i.e., always decode something without error. |
| public static final Convert. | PREJDK14
Do validation in accordance with the pre-JDK 1.4 Java class file format,
which allows (a) the NUL character |
| public static final Convert. | STRICT
Do strict validation. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | |
| public boolean | |
| public static Convert. | |
| public static Convert. |
| allowAnything | back to summary |
|---|---|
| private final boolean allowAnything | |
| allowLongEncoding | back to summary |
|---|---|
| private final boolean allowLongEncoding | |
| allowSingleByteNul | back to summary |
|---|---|
| private final boolean allowSingleByteNul | |
| NONE | back to summary |
|---|---|
| public static final Convert. Do zero validation of UTF-8, i.e., always decode something without error.
When this is used, | |
| PREJDK14 | back to summary |
|---|---|
| public static final Convert. Do validation in accordance with the pre-JDK 1.4 Java class file format,
which allows (a) the NUL character | |
| STRICT | back to summary |
|---|---|
| public static final Convert. Do strict validation. At this level, each character has only one valid encoding. | |
| Validation | back to summary |
|---|---|
| private Validation(boolean allowSingleByteNul, boolean allowLongEncoding, boolean allowAnything) | |
| allowAnything | back to summary |
|---|---|
| public boolean allowAnything() Whether to allow anything, including truncated characters and bogus flag bits. | |
| allowLongEncoding | back to summary |
|---|---|
| public boolean allowLongEncoding() Whether to allow characters to be encoded using more bytes than required. | |
| allowSingleByteNul | back to summary |
|---|---|
| public boolean allowSingleByteNul() Whether to allow the NUL character | |
| valueOf | back to summary |
|---|---|
| public static Convert. | |
| values | back to summary |
|---|---|
| public static Convert. | |