Last active
December 18, 2015 07:09
-
-
Save dalewking/5744791 to your computer and use it in GitHub Desktop.
Example of streaming text data to client in Scala on Play Framework 2.1 using OutputStream. It took me a long time to figure out how to get this working, so in case it helps someone else, here it is. The >>> Enumerator.eof is very important other wise it hangs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index = Action { | |
val output = Enumerator.outputStream | |
{ | |
o => | |
val out = new PrintWriter(new OutputStreamWriter(o, "utf8"), true) | |
for(i <- 1 to 5) | |
{ | |
out.println(s"Hello $i") | |
} | |
out.close() | |
} | |
Ok.stream(output >>> Enumerator.eof).withHeaders( | |
"Content-Type"->"text/plain; charset=utf-8" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment