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