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

documentaiton and reality for InputStream.read() do not agree

    XMLWordPrintable

Details

    • 0.9internal
    • sparc
    • solaris_2.3
    • Not verified

    Description

      The documentation for InputStream.read() says that it returns
      -1 on EOF, but the simple program below that reads from a network
      subclass of InputStream returns 0 when the end of the stream is reached.

      Save the following in Grab.oak and compile with oakc.
      Invoke it with "oaki grab http://www/~csw/"
      and notice that at the end of the stream the read() returns 0, not -1.

      import oak.io.*;
      import net.www.http.HttpClient;
      import net.www.html.URL;
       
      public class Grab extends HttpClient {
          public Grab(String url) {
              super(new URL(null, url));
          }
       
          protected void processRequest(String name) {
              InputStream dis = serverInput;
              int n;
              byte buf[] = new byte[1024];
       
              while ((n = dis.read(buf)) != -1) {
                  System.err.println("n="+n);
                  System.out.write(buf, 0, n);
              }
              System.out.flush();
              dis.close();
          }
       
          public static void main(String args[]) {
              try {
                  Grab grab = new Grab(args[0]);
              } catch (Exception e) {
                  System.err.println("err");
                  System.err.println(e);
                  e.printStackTrace();
              }
          }
       
      }

      Attachments

        Activity

          People

            ahoffsunw Arthur Hoff (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: