Slide 48
Slide 48 text
class Pattern3Controller @Inject()(implicit ec: SlowWriterExecutionContext)
extends InjectedController {
def exec: Action[AnyContent] = Action { _ =>
Result(
ResponseHeader(200, Map(CONTENT_DISPOSITION -> "attachment")),
HttpEntity.Streamed(createSource, None, None)
)
}
private def createSource: Source[ByteString, _] = {
StreamConverters.fromInputStream { () =>
val in = new PipedInputStream()
val out = new PipedOutputStream(in)
Future(Using(out)(o => someWrite(o)))
in
}
}