Java File Content Header

The built in method setContentLength() from the response object in Java will only accept an Integer, and therefore limit the content length to that of the max integer on the system architecture. (So therefore, about 2Gb for files being returned).

In order to overcome this limitation, use the addHeaders method rather than the provided method:

resp.addHeader("Content-Length", Long.toString(f.length()));
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s