public class CharsetConverter
extends java.lang.Object
This class trades use of the heap for speed by pre-calculating the conversions and creating conversion "tables". The resulting conversion operation is a simple array de-reference.
Modifier and Type | Field and Description |
---|---|
private static byte[] |
allBytes
All possible byte values.
|
private char[] |
byteToChar
Simple byte to character conversion mapping.
|
private byte[] |
charToByte
Simple character to byte conversion mapping.
|
private int |
offset
Smallest character value of the character to byte mapping range.
|
Constructor and Description |
---|
CharsetConverter(java.lang.String cset)
Create an instance that converts between Unicode and the given
character set.
|
Modifier and Type | Method and Description |
---|---|
byte |
toByte(char ch)
Convert the given Unicode character into the corresponding number in
the represented character set.
|
char |
toChar(byte b)
Convert the given byte into the corresponding Unicode character in
the represented character set.
|
char |
toChar(int i)
Convert the given number into the corresponding Unicode character in
the represented character set.
|
int |
toInt(char ch)
Convert the given Unicode character into the corresponding number in
the represented character set.
|
private static byte[] allBytes
private char[] byteToChar
private byte[] charToByte
private int offset
public CharsetConverter(java.lang.String cset)
cset
- The character set.public int toInt(char ch)
ch
- The Unicode character to convert.public byte toByte(char ch)
ch
- The Unicode character to convert.public char toChar(int i)
i
- The number to convert.public char toChar(byte b)
b
- The byte to convert.