Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:14:29+00:00 2026-06-11T23:14:29+00:00

Im trying to achieve something similar to the first example under Sending large amounts

  • 0

Im trying to achieve something similar to the first example under “Sending large amounts of data” at http://www.playframework.org/documentation/2.0/ScalaStream.

What I am doing differently is that I have more than one file that I want to concatenate in the response. It looks like this:

def index = Action {

  val file1 = new java.io.File("/tmp/fileToServe1.pdf")
  val fileContent1: Enumerator[Array[Byte]] = Enumerator.fromFile(file1)    

  val file2 = new java.io.File("/tmp/fileToServe2.pdf")
  val fileContent2: Enumerator[Array[Byte]] = Enumerator.fromFile(file2)   

  SimpleResult(
    header = ResponseHeader(200),
    body = fileContent1 andThen fileContent2
  )

}

What happens is that only the contents of the first file is in the response.

Something slightly simpler like below works fine though:

fileContent1 = Enumerator("blah" getBytes)
fileContent2 = Enumerator("more blah" getBytes)

SimpleResult(
  header = ResponseHeader(200),
  body = fileContent1 andThen fileContent2
)

What am I getting wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:14:30+00:00Added an answer on June 11, 2026 at 11:14 pm

    I’ve got most of this from reading through the play code so I might have misunderstood, but from what I can see: the Enumerator.fromFile function(Iteratee.scala [docs][src]) creates an enumerator which when applied to an Iteratee[Byte, Byte] appends an Input.EOF to the output of the Iteratee when it’s done reading from the file.

    According to the Play! docs example that you linked to you’re supposed to manually append an Input.EOF (alias of Enumerator.eof) at the end of the enumerator. I would think that, having an Input.EOF automatically appended to the end of the file’s byte array is the reason that you’re getting only one file returned.

    The equivalent simpler example in the play console would be:

    scala> val fileContent1 = Enumerator("blah") andThen Enumerator.eof
    fileContent1: play.api.libs.iteratee.Enumerator[java.lang.String] = play.api.libs.iteratee.Enumerator$$anon$23@2256deba
    
    scala> val fileContent2 = Enumerator(" and more blah") andThen Enumerator.eof
    fileContent2: play.api.libs.iteratee.Enumerator[java.lang.String] = play.api.libs.iteratee.Enumerator$$anon$23@7ddeef8a
    
    scala> val it: Iteratee[String, String] = Iteratee.consume[String]()
    it: play.api.libs.iteratee.Iteratee[String,String] = play.api.libs.iteratee.Iteratee$$anon$18@6fc6ce97
    
    scala> Iteratee.flatten((fileContent1 andThen fileContent2) |>> it).run.value.get
    res9: String = blah
    

    The fix, although I haven’t tried this yet would be to go a few levels deeper and use the Enumerator.fromCallback function directly and pass it a custom retriever function that keeps returning Array[Byte]s until all the files that you want to concatenate have been read. Refer to the implementation of the fromStream function to see what the default is and how to modify it.

    An example of how to do this (adapted from Enumerator.fromStream):

    def fromFiles(files: List[java.io.File], chunkSize: Int = 1024 * 8): Enumerator[Array[Byte]] = {
      val inputs = files.map { new java.io.FileInputStream(_) }
      var inputsLeftToRead = inputs
      Enumerator.fromCallback(() => {
        def promiseOfChunkReadFromFile(inputs: List[java.io.FileInputStream]): Promise[Option[Array[Byte]]] = {
          val buffer = new Array[Byte](chunkSize)
          (inputs.head.read(buffer), inputs.tail.headOption) match {
            case (-1, Some(_)) => {
              inputsLeftToRead = inputs.tail
              promiseOfChunkReadFromFile(inputsLeftToRead)
            }
            case (-1, None) => Promise.pure(None)
            case (read, _) => {
              val input = new Array[Byte](read)
              System.arraycopy(buffer, 0, input, 0, read)
              Promise.pure(Some(input))
            }
          }
        }
        promiseOfChunkReadFromFile(inputs)
      }, {() => inputs.foreach(_.close())})
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to achieve something similar to this: http://rickosborne.org/blog/2008/01/generating-scalable-stretchy-and-smart-graphics-with-coldfusion-part-2/ but inside tags.
What I'm trying to achieve is something similar to an Add-on called Live Http
I'm trying to achieve something similar to jQuery Glow or this fiddle . Specifically
I am trying to achieve something similar to the way the heading of a
Im trying to achieve something similar to Apples Contact.app. When the user press Edit
I am trying to achieve something similar to the following code snippet. As the
I'm trying to achieve something similar to this: public void execute(){ RandomClass item =
im trying to achieve something but i dont really know how I have set
I am trying to achieve something like this. The Expandable List consists of the
I am trying to achieve something in MySQL but even with all the answers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.