0

I'm trying to download a file from a url:

 try (FileOutputStream outputStream = new FileOutputStream(tmpFile)) {  
      downloadFromUrl(url, outputStream
 }  

 private void downloadFromUrl(URL url, FileOutputStream outputStream) throws IOException {        
        URLConnection urlConn = url.openConnection();
        InputStream is = urlConn.getInputStream(); //get connection inputstream

        byte[] buffer = new byte[4096]; //declare 4KB buffer
        int len;

        while ((len = is.read(buffer)) > 0) {
            outputStream.write(buffer, 0, len);
        }
     }
  }

I'm failing on:(in the line while ((len = is.read(buffer)) > 0) {)

The error message:

javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
    java.util.concurrent.ExecutionException: javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:206)
azro
  • 35,213
  • 7
  • 25
  • 55
Yosefarr
  • 561
  • 3
  • 10
  • 21

0 Answers0