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

(cs) jdk regression:OutputStreamWriter.write incorrectly writes valid chars

XMLWordPrintable

    • sparc
    • solaris_2.6



      Name: auR10023 Date: 05/25/2001



      OutputStreamWriter.write(char[]) incorrectly writes valid chars in 8859_1
      encoding.

      Here is the test demonstrating the bug:

      import java.io.*;

      -----------CharacterEncodingTest01.java----------

      public class CharacterEncodingTest01 {

          public static void main(String[] args) {
              String encoding = args[0];
              try {
                  char chars[] = {
                      'A', 'B',
                      '\uFFF0',
                      'a', 'b'
                  };
                  ByteArrayOutputStream baos = new ByteArrayOutputStream( );
                  OutputStreamWriter writer = new OutputStreamWriter( baos, encoding );
                  writer.write( chars );
                  writer.flush();
                  byte[] bytes = baos.toByteArray();
                  System.out.println("TO STRING: " + baos.toString());

                  if( bytes.length < chars.length ) {
                       System.out.println( "Incorrect number of bytes written: " +
                              bytes.length );
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }

      #> java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      #> java -cp . CharacterEncodingTest01 8859_1
      TO STRING: AB?b
      Incorrect number of bytes written: 4


      #> java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

      #> java -cp . CharacterEncodingTest01 8859_1
      TO STRING: AB?ab

      ======================================================================

            mr Mark Reinhold
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: