My C program opens a pipe and gets a file descriptor. Then it start a JVM with JNI and sends the file descriptor to the Java side. Is it now possible for me to write data to this pipe using the file descriptor from the Java code?

Finlay McWalter

Unfortunately, the java.io class that handles file descriptors (java.io.FileDescriptor) doesn't allow you to construct a new one from an integer (which is really what you want).

So, the only thing you can do is to create a new, specialized subclass of java.io.OutputStream (in practice you'd probably subclass BufferedOutputStream) which would take an integer file descriptor as a constructor argument. You'd then have to rewrite the functionality of java.io.FileOutputStream yourself, including the native code and JNI bridge. This is a bit of a pain, but it's not especially difficult.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact