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?
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?
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.
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.
Content-Length
header so that the client knows how much data is left