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

Cannot read byte streams encoded in UTF8

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 1.1.3
    • 1.1.2
    • core-libs
    • None
    • b01
    • sparc
    • solaris_2.5.1
    • Not verified

    Description

      An InputStreamReader using the UTF8 encoding produces an erroneous character
      stream, as demonstrated by the following program.

      --------

      import java.io.*;

      public class UTF8 {

          public static void main(String[] args) {
      try {
      Reader in = new InputStreamReader(System.in, "UTF8");
      char buf[] = new char[10];
      int n;
      while ((n = in.read(buf)) >= 0) {
      System.out.println(new String(buf, 0, n));
      }
      } catch (Exception x) {
      x.printStackTrace();
      }
          }

      }

      --------

      % java UTF8 <UTF8.java
       
      import ja
      tic void m
      new InputS
      [] = new c
      (buf)) >=
      n));
                  
      race();
              }
      %

      --------

      The above command should cause the entire program to be printed.

      Attachments

        Issue Links

          Activity

            People

              mr Mark Reinhold
              mr Mark Reinhold
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: