*/
public void TestMBCS(){
{
// Encoder: from Unicode conversion
CharsetEncoder encoderICU = new CharsetProviderICU().charsetForName("ibm-971").newEncoder();
ByteBuffer out = ByteBuffer.allocate(6);
encoderICU.onUnmappableCharacter(CodingErrorAction.REPLACE);
CoderResult result = encoderICU.encode(CharBuffer.wrap("\u0131\u0061\u00a1"), out, true);
if(!result.isError()){
byte[] expected = {(byte)0xA9, (byte)0xA5, (byte)0xAF, (byte)0xFE, (byte)0xA2, (byte)0xAE};
if(!equals(expected, out.array())){
errln("Did not get the expected result for substitution bytes. Got: "+
hex(out.array()));
}
logln("Output: "+ hex(out.array()));
}else{
errln("Encode operation failed for encoder: "+encoderICU.toString());
}
}
{
// Decoder: to Unicode conversion
CharsetDecoder decoderICU = new CharsetProviderICU().charsetForName("ibm-971").newDecoder();
CharBuffer out = CharBuffer.allocate(3);
decoderICU.onMalformedInput(CodingErrorAction.REPLACE);
CoderResult result = decoderICU.decode(ByteBuffer.wrap(new byte[] { (byte)0xA2, (byte)0xAE, (byte)0x12, (byte)0x34, (byte)0xEF, (byte)0xDC }), out, true);
if(!result.isError()){
char[] expected = {'\u00a1', '\ufffd', '\u6676'};