String.getBytes(charset) による EBCDIC への String 変換は、少なくとも 1 つの偽の結果を提供します。文字「a」は 0x3f になりますが、0x81 である必要があります。
public static void convert() throws UnsupportedEncodingException {
String data="abcABC";
String ebcdic = "IBM-1047";
String ascii = "ISO-8859-1";
System.out.printf("Charset %s is supported: %s\n", ebcdic, Charset.isSupported(ebcdic));
String result= new String(data.getBytes(ebcdic));
System.out.printf("EBCDIC: %s\n",asHex(result.getBytes()));
System.out.printf("Charset %s is supported: %s\n", ascii, Charset.isSupported(ascii));
result= new String(data.getBytes(ascii));
System.out.printf("ASCII: %s\n",asHex(result.getBytes()));
}
public static String asHex(byte[] buf) {
char[] HEX_CHARS = "0123456789abcdef".toCharArray();
char[] chars = new char[2 * buf.length];
for (int i = 0; i < buf.length; ++i)
{
chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
}
return new String(chars);
}
結果は次のとおりです。
- 文字セット IBM-1047 がサポートされています: true
- EBCDIC: 3f8283c1c2c3
- 文字セット ISO-8859-1 がサポートされています: true
- アスキー: 616263414243
これについて私にできることはありますか?