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

ImageOutputStreamImpl.writeChars(String) ignores the current byte order setting

XMLWordPrintable

    • beta2
    • generic
    • generic
    • Not verified



      Name: vpR10011 Date: 05/17/2001



      Specification of the class javax.imageio.stream.ImageOutputStreamImpl says:

      public void writeChars(String s) throws IOException

      Writes a string to the output stream. For every character in the string s,
      taken in order, two bytes are written to the output stream, ordered according
      to the current byte order setting. If network byte order is being used,
      the high-order byte is written first; the order is reversed otherwise.
      ..."



      But this method ignores the current byte order setting.

      To reproduce this bug run the following test:
      ---------------------test.java--------------
      import java.io.*;
      import javax.imageio.stream.*;

      public class test {
          public static void main(String[] argv) {
              OutputStream os = (OutputStream) new ByteArrayOutputStream();
              MemoryCacheImageOutputStream iosI =
                      new MemoryCacheImageOutputStream(os);
              try {
                  byte [] b1 = new byte[2];
                  byte [] b2 = new byte[2];

                  iosI.setByteOrder(true);
                  iosI.writeChars("1");
                  iosI.seek(0);
                  iosI.read(b1);
                  System.out.println("getByteOrder() = " + iosI.getByteOrder()
                         + " b1[0]=" + b1[0] + " b1[1]=" + b1[1]);

                  iosI.setByteOrder(false);
                  iosI.seek(0);
                  iosI.writeChars("1");
                  iosI.seek(0);
                  iosI.read(b2);
                  System.out.println("getByteOrder() = " + iosI.getByteOrder()
                         + " b2[0]=" + b2[0] + " b2[1]=" + b2[1]);

                  if (b1[0] == b2[1] && b1[1] == b2[0]) {
                      System.out.println("Passed");
                  } else {
                      System.out.println("Failed");
                  }
              } catch (Exception e) {
                  System.out.println("Failed: unexpected exception " + e);
              }
          }
      }
      -------------------log----------------------
      % java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b64)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b64, mixed mode)
      % java test
      getByteOrder() = true b1[0]=0 b1[1]=49
      getByteOrder() = false b2[0]=0 b2[1]=49
      Failed: b1[0]=0 b1[1]=49 b2[0]=0 b2[1]=49
      --------------------------------------------

      This bug causes failure of the new JCK test
      api/javax_imageio/stream/ImageOutputStreamImpl/index.html#writeChars



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

            dricesunw Daniel Rice (Inactive)
            verapsunw Verap Verap (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: