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

InputStreamReader hangs on UTF-16 encoded files >8kB

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • x86
    • windows_2000



      Name: nt126004 Date: 01/24/2002


      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

      I tried to read a UTF-16 encoded file, and the VM hangs when reading a
      character from it. Below is the code I used for testing.
      The freeze happens when the input-file is bigger than 8198 bytes!
      I used a plain html-file for testing, converted to unicode with the BOM in
      the beginning. Previously I worked with JDK1.3.1 where the error didn't
      happen.

      After a search in the bugparade I found something about a problem with the
      names of the encodings (Bug #4513767), and I tried "UTF16" as encoding,
      and this works!!!!

      This is the class I used for testing:
      import java.io.*;
      public class ReadUni {
      public static void main(String args[]) throws Exception {
      File file = new File(args[0]);
      String enc = "UTF-16";
      InputStreamReader r = new InputStreamReader(new FileInputStream
      (file), enc);
      int c;
      System.out.println("showing file " + file + ":");
      while((c=r.read()) != -1) {
      System.out.print((char)c);
      }
      System.out.println();
      System.out.println("File displayed!");
      }
      }
      (Review ID: 135578)
      ======================================================================

            iris Iris Clark
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: