-
Bug
-
Resolution: Fixed
-
P3
-
0.9
-
0.9internal
-
sparc
-
solaris_2.3
-
Not verified
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();
}
}
}
-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();
}
}
}