开发者

Return binary stream as response to request playframework

i have problem with returning binary stream from play framework. According to documentation, the framework should automatically return binary output if it finds that the controller method returns either Stream or File. Well my method returns a Stream[Byte] but the framework returns "Stream(100, ?)" rather then the binary stream.

What do i do wrong? Thanks for the answers, Tomas Herman


edit

ok in case anyone needs this in the future, it looks like i somehow hacked it together. I just build a string from the Stream and return that. It seems to be working correctly but i'm sure there is some better solution.

example:

val builder = n开发者_StackOverflowew StringBuilder()
builder.clear
stream foreach { x=> builder.append(x.toChar)}
val res = builder.toString

where res is what your controller method is supposed to return


You might have gotten what you need. Stream(100, ?) is a Stream whose first value is 100, and the remaining values have not yet been evaluated. To see it fully, try printing stream mkString ("Stream(", ", ", ")").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜