3

I am downloading mp3 and image files using "org.apache.commons.io.FileUtils" in the following code successfully on windows 7:

FileUtils.copyURLToFile(new URL(urlString),myFile);

but on mac os x Yosemite version 10.10.2 (14C1514) I get this exception after few downloads:

   java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:789)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)

I have tried adding a timeout

FileUtils.copyURLToFile(new URL(url),myFile ,60000,60000);

or even using other methods

URLConnection conn = new URL(url).openConnection();
InputStream is = conn.getInputStream();
OutputStream outstream = new FileOutputStream(myFile);
byte[] buffer = new byte[4096];
int len;
while ((len = is.read(buffer)) > 0) {
    outstream.write(buffer, 0, len);
}
outstream.close();

Update:

I tried to disable WiFi (to avoid any connectivity bugs as mentioned by @john) and used wired ethernet but still have the same error after few downloads, any help is appreciated.

Amr Lotfy
  • 2,937
  • 5
  • 36
  • 56
  • 1
    Are you sure your WiFi isn't disconnecting during the test? Recently I had to upgrade my 2011 Macbook Pro because there was a bug that caused the WiFi to drop periodically. This might be happening if you are downloading a large file. I would upgrade to `10.10.3` and try the test again. – John Apr 24 '15 at 17:27
  • 1
    From the [update](https://support.apple.com/en-us/HT204490): `Improves Wi-Fi performance and connectivity in various usage scenarios` – John Apr 24 '15 at 17:31
  • I tried using wired connection (disabled wifi) but still have same problem, thanks @john that was close :) – Amr Lotfy Apr 25 '15 at 07:12

1 Answers1

0

That was ISP related, issue resolved.

Amr Lotfy
  • 2,937
  • 5
  • 36
  • 56