title: Spring MVC : large files for download, OutOfMemoryException
body: <p>How to provide large files for download through spring controller ? I followed few discussions on similar topic :</p>
  
  <p><a href="https://stackoverflow.com/questions/5673260/downloading-a-file-from-spring-controllers">Downloading a file from spring controllers</a></p>
  
  <p>but those solutions fails for large files ~ 300mb - 600mb.
  I am getting OutOfMemoryException on the last line :</p>
  
  <pre><code>@RequestMapping(value = "/file/{dummyparam}.pdf", method = RequestMethod.GET, produces=MediaType.APPLICATION_OCTET_STREAM_VALUE)
  public @ResponseBody byte[] getFile(@PathVariable("dummyparam") String dummyparam, HttpServletResponse response) {
  .
  .       
  InputStream is = new FileInputStream(resultFile);
  
  response.setHeader("Content-Disposition", "attachment; filename=\"dummyname " + dummyparam + ".pdf\"");
  .
  .         
  return IOUtils.toByteArray(is);
  </code></pre>
  
  <p>My (naive) assumption was that IOUtils will handle even large files but this is not obviously happening. Is there any way how to split file into chunks as download is in progress ? Files are usually around 300 - 600mb large. Max number of concurrent downloads is estimated to 10. </p>
  
  <p>Easy way would be to link files as static content in the webserver directory but we would like to try do it in within our Spring app.</p>