public class Test {

    private static final String WINDOWS31J  = "Windows-31J";

    private static final String UTF16  = "UTF_16BE";

    public static void main(String[] args) {
        test(0x81, 0xE8, 0x81, 0xE8);
        test(0x81, 0xE8, 0x81, 0xE9, 0x81, 0xE8);
    }

    private static void test(Integer... data) {
        try {
            byte[] b1 = getBytes(data);
            String s  = new String(b1, WINDOWS31J);
            byte[] b2 = s.getBytes(UTF16);
            
            System.out.println();
            System.out.println(String.format("%-20s : %s", WINDOWS31J, hexdump(b1)));
            System.out.println(String.format("%-20s : %s", UTF16,      hexdump(b2)));
            System.out.println(String.format("%-20s : %s", "String",   s));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    
    
    private static byte[] getBytes(Integer... data) {
        byte[] b = new byte[data.length];

        for (int i = 0; i < data.length; i++) {
            b[i] = (byte) (data[i] & 0xff);
        }
        
        return b;
    }
    
    
    private static String hexdump(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        
        for (byte b : bytes) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            
            sb.append(String.format("%02X", b));
        }
        
        return sb.toString();
    }
}
