Sharing output streams through a JNI interface
问题 I am writing a Java application that uses a C++ library through a JNI interface. The C++ library creates objects of type Foo , which are duly passed up through JNI to Java. Suppose the library has an output function void Foo::print(std::ostream &os) and I have a Java OutputStream out . How can I invoke Foo::print from Java so that the output appears on out ? Is there any way to coerce the OutputStream to a std::ostream in the JNI layer? Can I capture the output in a buffer the JNI layer and