お世話になります。
UnicodeからShif-JISに変換を行いたく、String#getBytes(String charsetName)を使用していました。
単体テストも作成していまして、Android 4.3 (Jelly Bean)までの環境では
正常にパスしていたのですが、Android 4.4 (KitKat)に環境を変更して
確認したところエラーになってしまいました。
どうやら4.4ではgetBytesで取得されるバイナリ配列の末尾1byteが欠けてしまっているようです。
期待: 0x82, 0xA0
結果: 0x82
この場合、どのような対処を行えばよいのでしょうか?
//参考ソース
public class TestSample extends AndroidTestCase {
public void test_getBytes() throws UnsupportedEncodingException{
String unicode = "あ";
byte[] sjis = unicode.getBytes("Shift_JIS");
byte[] expected = new byte[] {(byte)0x82, (byte)0xA0};
assertEquals(2, sjis.length); // 2byteであること
assertTrue(Arrays.equals(expected, sjis)); // Shift_JISであること
}
}
//以上