2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2001 by Sun Microsystems, Inc. 2N/A * All rights reserved. 2N/A// Author: James Kempf 2N/A// Created On: Fri Sep 11 13:24:02 1998 2N/A// Last Modified By: James Kempf 2N/A// Last Modified On: Wed Oct 28 14:33:02 1998 2N/A * The IANACharCode class supports static methods for decoding IANA 2N/A * character codes into strings appropriate for the Java Writer subclass 2N/A * encoding String arguments, and for encoding the String descriptions 2N/A * of character codings into the integer codes. Ideally, Java itself 2N/A * should support this. 2N/A * @author James Kempf 2N/A // Character code descriptors. These can be used with the Java 2N/A // character encoding utilities. For Unicode, we use little on 2N/A // Error code for misidentified character set. 2N/A // First two bytes indicate that string is big/little endian Unicode. 2N/A // If this flag isn't set, then big endian is assumed and we 2N/A // must add the big endian bytes on every call. 2N/A {(
byte)
0xFF, (
byte)
0xFE};
2N/A {(
byte)
0xFE, (
byte)
0xFF};
2N/A * Encode the String describing a character encoding into 2N/A * the approprate integer descriptor code. 2N/A * @param encoding The String describing the encoding. 2N/A * @exception ServiceLocationCharSetNotUnderstoodException Thrown if the 2N/A * String is not recognized. 2N/A "v1_unsupported_encoding",
2N/A * Decode the integer describing a character encoding into 2N/A * the approprate String descriptor. 2N/A * @param code The integer coding the String set. 2N/A * @exception ServiceLocationCharSetNotUnderstoodException Thrown if the 2N/A * integer is not recognized. 2N/A "v1_unsupported_encoding",
2N/A * Return a string of integers giving the character's encoding in 2N/A * the character set passed in as encoding. 2N/A * @param c The character to escape. 2N/A * @param encoding The character set encoding to use. 2N/A * @return The character as a string of integers for the encoding. 2N/A * @exception ServiceLocationException Thrown if the encoding is not 2N/A * recognized, if the character's encoding 2N/A * has more than 8 bytes or if the sign bit gets turned on. 2N/A "v1_unsupported_encoding",
2N/A // Assemble the character code based on the encoding type. 2N/A code = (
int)(b[
0] &
0xFF);
// control bytes... 2N/A "v1_charcode_error",
2N/A "v1_charcode_error",
2N/A "v1_charcode_error",
2N/A * Unescape the character encoded as the string. 2N/A * @param ch The character as a string of Integers. 2N/A * @param encoding The character set encoding to use. 2N/A * @return The character. 2N/A * @exception ServiceLocationException Thrown if the string can't 2N/A * be parsed into an integer or if the encoding isn't 2N/A "v1_stringcode_error",
2N/A // Convert to bytes. We need to taylor the array size to the 2N/A // number of bytes because otherwise, in encodings that 2N/A // take less bytes, the resulting string will have garbage 2N/A // We create an array sized to the encoding. 2N/A "v1_stringcode_error",
2N/A "v1_stringcode_error",
2N/A // Make a string out of it. 2N/A "v1_unsupported_encoding",
2N/A // Determine from the flag bytes whether this is big or little endian 2N/A // Unicode. If there are no flag bytes, then just return UNICODE. 2N/A // We can`t tell from the byte header, so it's big endian. But 2N/A // since we need to add the byte header, we say we don't know. 2N/A // Add the big endian flag to a Unicode string.