Sharing output streams through a JNI interface
Posted
by Chris Conway
on Stack Overflow
See other posts from Stack Overflow
or by Chris Conway
Published on 2009-09-16T20:07:00Z
Indexed on
2010/04/27
17:33 UTC
Read the original article
Hit count: 388
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 then copy it into out
?
© Stack Overflow or respective owner