users@glassfish.java.net

Re: Forcing chunked encoding while downloading a large file?

From: Martin Matula <martin.matula_at_oracle.com>
Date: Tue, 8 May 2012 11:10:07 +0200

Hi Kevin,
That should not be happening. For InputStream Jersey returns -1 as the content length - i.e. does not try to buffer the entity. For the File it reads it using File.length() method.
Are you using any filters in your application? E.g. the logging filter would cause that the entity would get buffered.
Martin

On May 4, 2012, at 11:24 PM, Kevin Regan wrote:

> I’m downloading a large file with Jersey/Glassfish and I’m seeing a java.lang.OutOfMemoryError.
>
> I’m returning a FileInputStream (also tried File) from the Jersey handler and it looks to be attempting to write the file to a ByteArrayOutputStream before returning it.
>
> Is there any way to force Jersey/Glassfish to stream this large binary file to the client through either chunked encoding or by not setting CONTENT-LENGTH?
>
> Sincerely,
> Kevin Regan