title: Download zip file using java11 HttpClient.sendAsync()
body: <p>I'm trying to download a zip file through a java program using GitHub API.</p>
  <p>The program I'm using is the following:</p>
  <pre><code>public static void main(String[] args) {
          // create client
          HttpClient client = HttpClient.newHttpClient();
  
          // create request
          HttpRequest request = HttpRequest.newBuilder().uri(URI.create(&quot;https://api.github.com/repos/:owner/:repo/zipball/:ref&quot;)).build();
  
          // use the client to send the asynchronous request
          InputStream is = client.sendAsync(request, BodyHandlers.ofInputStream())
                  .thenApply(HttpResponse::body).join();
          try {
              FileOutputStream out = new FileOutputStream(&quot;outputZipFile.zip&quot;);
              copy(is,out,1024);
              out.close();
          }catch(Exception e) {}
          
          
          
      }
  
      private static void copy(InputStream is, FileOutputStream out, int i) {
          // TODO Auto-generated method stub
          byte[] buf = new byte[i];
          try {
              int n = is.read(buf);
              while(n&gt;=0) {
                  out.write(buf,0,n);
                  n=is.read(buf);
              }
              out.flush();
          }catch(IOException ioe) {
              System.out.println(ioe.getStackTrace());
          }
          
      }
  </code></pre>
  <p>When I try to run this I get empty body so the output file will be empty as well.
  I noticed that using HttpURLConnection insted of Java11 HttpClient makes it work but I'd prefer to use this Java11 feature in order to send asynchronous requests.</p>
  <p>I can't understand what I'm doing wrong.</p>
  <p><strong>EDIT</strong>: The HttpURLConnection code I'm using at the moment is the following:</p>
  <pre><code>private void downloadVersion(String sha, String outputDestination) {
              try {
                  URL url = new URL( getDownloadQuery(sha) );
                  
                  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                  if(authToken!=null) 
                      connection.setRequestProperty(&quot;Authorization&quot;, &quot;Bearer &quot; + authToken) ;
                  connection.setRequestMethod(&quot;GET&quot;);
                  
                  InputStream in = connection.getInputStream();
      
                  FileOutputStream out = new FileOutputStream(outputDestination);
                  copy(in, out, 1024);
                  out.close();
              } catch (Exception e) {}
              
          }
  </code></pre>