Suppose I am passed an OutputStream
variable. Is there any way to detect if the source of the OutputStream
is an open file, or open socket etc?
If it is not possible, is it better if I know the variable is of type FileOutputStream
, and hence I can get its FileDescriptor
. Thank you.
UPDATE:
Each FileOutputStream instance has a FileDescriptor. I couldn't distinguish its source because from the Java document:
Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. The main practical use for a file descriptor is to create a FileInputStream or FileOutputStream to contain it.
UPDATE2:
I'm developing an automated tool, built on top of a customized JVM, to analyze Java bytecode, and determine how many bytes the program writes to a file or sends over the socket, etc (in very simple programs). File, Socket etc are then processed differently.
The customized JVM lets me know when it executes the bytecode instruction INVOKEVIRTUAL
, and I can check that the callee is of OutputStream. Now what I need to do is to determine where this OutputStream writes to File/Socket etc.