Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6226510

ISO-2022-JP encoder's reset() method noop; should revert to ASCII

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • None

      The self-explanatory program below should not throw an exception

      ---------------------------------------------------------------------
      import java.nio.*;
      import java.nio.charset.*;

      class Reset {

          public static void main(String[] args) throws Exception {
      if (! (encode(true).equals(encode(false))))
      throw new Exception("Mismatch!");
          }

          static String encode(boolean reuseEncoder) {
      String s = "\u3042\u3043\u3044";

      CharsetEncoder e = Charset.forName("ISO-2022-JP").newEncoder();

      if (reuseEncoder) {
      // I'm turning japanese. Yes I'm turning japanese. Yes I think so!
      e.encode(CharBuffer.wrap(s), ByteBuffer.allocate(64), true);

      // Should put encoder back into ASCII mode
      e.reset();
      }

      ByteBuffer bb = ByteBuffer.allocate(64);
      e.encode(CharBuffer.wrap(s), bb, true);
      e.flush(bb);
      bb.flip();
              StringBuilder sb = new StringBuilder();
              for (int i = 0; i < bb.limit(); i++)
      sb.append(String.format("%02x ", bb.get(i)));
      System.out.println(sb);
      return sb.toString();
          }
      }
      ---------------------------------------------------------------------
      ###@###.### 2005-2-08 03:13:25 GMT

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: