4

I need to retrieve from an Application Server (JBoss) a large file (gigabytes) and to avoid loading it in memory, I want to stream it through EJB.

Is it possible to take data out of an Application Server as a stream?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Mr.Eddart
  • 10,050
  • 13
  • 49
  • 77

2 Answers2

4

Create a HttpServlet, stream the file.

update Be careful with your header. You cannot set the ContentLength-Header via setContentLength(), because it only accept int.

You wil have to set it with: setHeader("Content-Length", (long)length)

Maybe this will be helpful: Using ServletOutputStream to write very large files in a Java servlet without memory issues

There is a limit, but it depends on the client-side. If the client will hold the file in the memory, it will not work.

Community
  • 1
  • 1
Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79
4

By EJB do you mean remote bean? These beans are typically based on RMI which in turn uses Java serialization. You cannot stream data using RMI.

However with servlets and HTTP this will be dead simple. Just open FileInputStream to your large file and copy it byte-by-byte to servlet output.

To remember:

  • Use input file buffering
  • At the very beginning set Content-Length header so that the client knows how much data is left
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674