I’m using a PDF library which writes data into an OutputStream. How can I serve this outputstream as a Result?
I used stuff from play-iteratees for this, but it seems that it no longer exists for Scala 2.13. I guess there might be something in StreamConverters, but I can’t figure out how to use it.
StreamConverters.asOutputStream().mapMaterializedValue { os => myRenderMethod(os) }
should be a possible solution.
However, that gives:
Rendering of response failed because response entity stream materialization failed with 'java.util.concurrent.TimeoutException'
That is with iText. When using the same technique for rendering Excel files using Apache POI I get a different error, but the common thing is that neither works.
So I’ve resorted to simply using a ByteArrayOutputStream and just serving it with .toByteArray. Which works perfectly.