title: Reading a file of larger size from server with spring rest api from the performance point of view
body: <p>I able to read the log file from the server and able to download the same successfully through spring rest API, now my query os that right now my input file size at the server is of 500 MB but anyhow if my file reaches to 1 GB, so in that case what modifications I need to do in the below piece of code to improve the performance </p>
  
  <pre><code>  @GetMapping("/download/{filename}")
      public ResponseEntity&lt;Resource&gt; download(@RequestParam String filename) throws IOException {
          File file = new File(SERVER_LOCATION + File.separator + filename + EXTENSION);
  
          HttpHeaders header = new HttpHeaders();
          header.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename + EXTENSION);
          header.add("Cache-Control", "no-cache, no-store, must-revalidate");
          header.add("Pragma", "no-cache");
          header.add("Expires", "0");
  
          Path path = get(file.getAbsolutePath());
          ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path));
  
          final ResponseEntity&lt;Resource&gt; resourceResponseEntity = ResponseEntity.ok()
                  .headers(header)
                  .contentLength(file.length())
                  .contentType(MediaType.parseMediaType("application/octet-stream"))
                  .body(resource);
          return resourceResponseEntity;
      }
  </code></pre>