It is not possible to use FileInputStream and FileOutputStream, according to
their defined interfaces. They fail to accomodate I/O properly; specifically,
they can't be used to faciliate proper two-way communication on Solaris
named-pipes. But the root problem seems to be related to their handling of
the FileDescriptor class, and occurs with any type of file. I will
explain it in terms of named-pipe files.
A named-pipe appears as a file in the I/O system, and, as a UNIX file type
"fifo" and should respond properly to basic file I/O operations. The
FileInputStream and FileOutputStream should work properly with this type
of file.
The failure can demonstrated by retreiving both an input and output stream
for a named-pipe (or an ordinary file), and letting the two stream objects
share a common file descriptor (that is, making them both be active
on the same connection). Having both streams pertain to the same
connection via a common file descriptor is possible because both the
FileInputStream and FileOutputStream classes accept a FileDescriptor
object in their constructors and both expose the FileDescriptor
via their 'getFD()' methods. The ability to share FD's for similar purposes
is clearly intentional.
STEPS TO REPRODUCE: (See attached .java program)
1. Use FileOutputStream to get an outputstream to a named-pipe.
2. Using the 'getFD()' method on the outputstream, get the FileDescriptor
3. Using the FileDescriptor obtained, instantiate a FileInputStream
(there is a constructor which accepts an FD).
4. Test the streams, by sending data into the output stream, which should
be received by a listener on the other side of the pipe.
5. The listener responds by sending data back down the pipe.
6. The Java side loops until the inputstream.available() method indicates
data has arrived [and can be read].
7. Use the inputstream.read() method to get the data.
8. An IOException: Bad file number is returned.
(The Bad File Number error will occur for both an named-pipe and ordinary
file when trying to do a read() or write() on the input-stream constructed
from the fd of the complimentary stream).
The fact that available() shows that data is available to read
further suggests that these mechanisms should work as implied.
- relates to
-
JDK-4411569 JVM stdin/stdout cannot be set to named pipe
-
- Open
-