Skip to content

Instantly share code, notes, and snippets.

@magro
Created May 11, 2014 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magro/83286ffc4a9a0caad36d to your computer and use it in GitHub Desktop.
Save magro/83286ffc4a9a0caad36d to your computer and use it in GitHub Desktop.
Play WS client: process large response
import play.api.libs.iteratee._
def fromStream(stream: OutputStream): Iteratee[Array[Byte], Unit] = Cont {
case e@Input.EOF =>
stream.close()
Done((), e)
case Input.El(data) =>
stream.write(data)
fromStream(stream)
case Input.Empty =>
fromStream(stream)
}
val outputStream: OutputStream = new BufferedOutputStream(new FileOutputStream(file))
val futureResponse = WS.url(url).withRequestTimeout(3000).get {
headers => fromStream(outputStream)
}.map(_.run)
@mariussoutier
Copy link

Done((), e) doesn't compile for me, found : [E]play.api.libs.iteratee.Step.Done[Unit,E] required: play.api.libs.iteratee.Iteratee[Array[Byte],Unit]. I had to add .it there and also to the end of Cont {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment