O'Reilly logo

Play Framework Essentials by Julien Richard-Foy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Streaming results using enumerators

Iteratees make it possible to consume streams of data in a non-blocking way. Conversely, enumerators produce data streams in a non-blocking way. They are useful when you need to send large results, or if your result is built from an intermittent data source. An Enumerator[A] object defines a stream of values of type A.

The simplest way to create an enumerator is to use one of the methods of the Enumerator object. For instance, you can easily convert a java.io.InputStream class or a java.io.File class to an Enumerator[Array[Byte]] object as follows:

import play.api.libs.iteratee.Enumerator
Enumerator.fromStream(inputStream)
Enumerator.fromFile(file)

To send a stream of data as a response body, it is better to explicitly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required