title: Rest template read response as stream and pass to spring controller(Get InputStream with rest Template)
body: <p>I have a url which download the large size zip file.It returns the response as stream.though file size is large first it returns 200(HTTPSTATUK.OK) and continues download.</p>
  <p>I have to implement a new spring controller which call the above url through rest template.I have to read the response returned by rest template and pass to controller.initially I have implemented in below way</p>
  <pre><code>     @GetMapping(&quot;/export/downloadFile&quot;)
          public ResponseEntity&lt;byte[]&gt; downloadData(Model model,
                                                         @ModelAttribute(EXCEPTION_COLLECTOR) ExceptionCollector exceptionCollector,
                                                         @RequestParam(&quot;userName&quot;) String userName,
                                                         @RequestParam(&quot;startDate&quot;) Date startDate,
                                                         @RequestParam(&quot;endDate&quot;) Date endDate,
                                                         @RequestParam(&quot;reason&quot;) String reason) {
  
     URI uri = /building url here/;
      
      return restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity&lt;&gt;(httpHeaders), byte[].class);
      
      }
  </code></pre>
  <p>since I am using ResponseEntity&lt;byte[]&gt; , rest template waits till entire file loaded into memory.so very frequently I am getting socket timeout issue.</p>
  <p>Do we have way to read the response as stream and return to controller.</p>
  <p>I found few things about restTemplate.execute .</p>
  <pre><code>restTemplate.execute(uri,HttpMethod.GET,requestCallBack,clientHttpResponse -&gt; {
                  File ret = File.createTempFile(&quot;download&quot;, &quot;.zip&quot;,new File(&quot;/Users/bokkavijay/Desktop&quot;));
                  StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret));
                  return ret;
              });
  </code></pre>
  <p>above snippet can copy the file to our local with out time out but this is not what I need.</p>
  <p><strong>how can we pipe the stream in clientHttpResponse to controller ?</strong></p>