Created
May 11, 2014 21:15
-
-
Save magro/83286ffc4a9a0caad36d to your computer and use it in GitHub Desktop.
Play WS client: process large response
This file contains hidden or 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
import play.api.libs.iteratee._ | |
def fromStream(stream: OutputStream): Iteratee[Array[Byte], Unit] = Cont { | |
case [email protected] => | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ofCont {}
.