java - Downloading large files via Spring MVC -


i have rest method downloading files works. but, seems download doesn't start on web client until file copied output stream, can take while large files.

@getmapping(value = "download-single-report") public void downloadsinglereport(httpservletresponse response) {      file dlfile = new file("some_path");      try {         response.setcontenttype("application/pdf");         response.setheader("content-disposition", "attachment; filename="+ dlfile.getname());         inputstream inputstream = new fileinputstream(dlfile);         ioutils.copy(inputstream, response.getoutputstream());         response.flushbuffer();     } catch (filenotfoundexception e) {         // error     } catch (ioexception e) {         // error         }     } 

is there way "stream" file such downloda starts begin writing output stream?

i have similar method takes multiple files , puts them in zip, adding each zip entry zip stream, , download begins after zip has been created:

        zipentry zipentry = new zipentry(entryname);         zipoutstream.putnextentry(zipentry);         ioutils.copy(filestream, zipoutstream); 

use

ioutils.copylarge(inputstream input, outputstream output) 

copy bytes large (over 2gb) inputstream outputstream. method buffers input internally, there no need use bufferedinputstream.

the buffer size given default_buffer_size.

or

ioutils.copylarge(inputstream input, outputstream output, byte[] buffer) 

copy bytes large (over 2gb) inputstream outputstream. method uses provided buffer, there no need use bufferedinputstream.

http://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/ioutils.html


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -