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

OutputStreamWriter and/or CharToByteConverter for JIS loses state

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.4
    • globalization



      Name: rm29839 Date: 11/12/97


      import java.io.*;

      // This program demonstrates a bug in OutputStreamWriter when using JIS

      // The correct output of this program should be
      // ESC $ B $ 4 ESC ( B ESC $ B $ _ ESC ( B
      // or something equivalent like
      // ESC $ B $ 4 $ _ ESC ( B
      // However, it outputs
      // ESC $ B $ 4 ESC ( B $ _ ESC ( B ESC ( B
      // which is erroneous.

      public class Jisbug {
        public static void main (String args[]) {
          int c;
          StringReader in;
          OutputStreamWriter out;

          try {
            in = new StringReader ("\u3054\u307f");
            out = new OutputStreamWriter (System.out, "JIS");
            while ((c=in.read()) > 0) {
              out.write (c);
            }
            in.close ();
            out.close ();
          } catch (UnsupportedEncodingException e) {
            System.err.println ("One or more unsupported encodings");
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
      (Review ID: 19524)
      ======================================================================

            sherman Xueming Shen
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: