[kaffe] InputStream#available() for System.in throws IOException

Ito Kazumitsu kaz at maczuka.gcd.org
Mon Aug 29 09:54:52 PDT 2005


Hi,

The program attached below throws java.io.IOException when run with
current CVS version of Kaffe.

Case 1: Terminal input
$ kaffe TestBufferedReader
aaaa
java.io.IOException: No such file or directory
   at gnu.java.nio.channels.FileChannelImpl.available (FileChannelImpl.java)
   at java.io.FileInputStream.available (FileInputStream.java:165)
   at java.io.FilterInputStream.available (FilterInputStream.java:129)
   at java.io.BufferedInputStream.read (BufferedInputStream.java:276)
   at java.io.FilterInputStream.read (FilterInputStream.java:173)
   at java.io.InputStreamReader.read (InputStreamReader.java:395)
   at java.io.BufferedReader.fill (BufferedReader.java:373)
   at java.io.BufferedReader.readLine (BufferedReader.java:475)
   at TestBufferedReader.main (TestBufferedReader.java:12)
java.io.IOException: No such file or directory

Case 2: Pipe
$ echo aaaa | kaffe TestBufferedReader     
java.io.IOException: No such file or directory
   at gnu.java.nio.channels.FileChannelImpl.available (FileChannelImpl.java)
   at java.io.FileInputStream.available (FileInputStream.java:165)
   at java.io.FilterInputStream.available (FilterInputStream.java:129)
   at java.io.BufferedInputStream.read (BufferedInputStream.java:276)
   at java.io.FilterInputStream.read (FilterInputStream.java:173)
   at java.io.InputStreamReader.read (InputStreamReader.java:395)
   at java.io.BufferedReader.fill (BufferedReader.java:373)
   at java.io.BufferedReader.readLine (BufferedReader.java:475)
   at TestBufferedReader.main (TestBufferedReader.java:12)
java.io.IOException: No such file or directory

Case 3: File input - OK
$ kaffe TestBufferedReader <TestBufferedReader.java 
$

Case 4: Here document - OK
$ kaffe TestBufferedReader <<EOF
> aaaa
> EOF
$

This error occurs on both FreeBSD and Linux.
Slight differences among operating systems are:

(1) On Linux 2.6.7-co-0.6.2, the message of the IOException is
    "Success" instead of "No such file or directory".

(2) On Linux 2.4.18-3, instead of throwing IOException, the program
    seems to go into a deadlock. But giving an argument to the
    program, we see the same IOException.

$ echo aaaa | kaffe TestBufferedReader US-ASCII
java.io.IOException: No such file or directory
   at gnu.java.nio.channels.FileChannelImpl.available (FileChannelImpl.java)
   at java.io.FileInputStream.available (FileInputStream.java:165)
   ...

And here is the program for testing.
import java.io.*;

public class TestBufferedReader {

    public static void main(String[] args) throws Exception {
      try {
	BufferedReader rdr = new BufferedReader(
            (args.length > 0 ?
              new InputStreamReader(System.in, args[0]) :
              new InputStreamReader(System.in)));
        while (true) {
            String s = rdr.readLine();
            if (s == null) break;
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        throw e;
      }
    }
}




More information about the kaffe mailing list