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

MemoryCacheImageOutputStream.read(byte[],int,int) returns incorrect value

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description



      Name: vpR10011 Date: 04/19/2001



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

      "public int read(byte[] b, int off, int len) throws IOException
          Description copied from interface: ImageInputStream
          Reads one or more bytes from the stream, up to len, and stores them
          into b starting at index off. The number of bytes read is returned. If no
          bytes can be read because the end of the stream has been reached, -1 is
          returned.
      ...
      Returns:
          the number of bytes actually read, or -1 to indicate EOF.
      ..."


      But if the end of the stream has been reached this method returns 0.

      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 mcos = new MemoryCacheImageOutputStream(os);
              byte [] b1 = {1, 2};
              byte [] b2 = new byte[10];
              int t;
              try {
                  mcos.write(b1);
                  System.out.println("length() = " + mcos.length());
                  mcos.seek(0);
                  t = mcos.read(b2, 0, b2.length);
                  System.out.println("read(byte[], int, int) returns " + t);
                  t = mcos.read(b2, 0, b2.length);
                  System.out.println("read(byte[], int, int) returns " + t);
                  System.out.println( t == -1 ? "Passed" : "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-b60)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)
      % java test
      length() = 2
      read(byte[], int, int) returns 2
      read(byte[], int, int) returns 0
      Failed




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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: