I'm working on writing a program to download very large files (~2GB) from a server. I've written the program to be able to resume partially finished downloads,
In order to simulate a bad internet connection, I've been pulling my ethernet cord out of my router while mid-download. Unfortunately, this causes my program to hang on the following call:
while((bytesRead = in.read(data)) > 0)
(Where bytesRead is an int, in is a BufferedInputStream built from an HttpURLConnection, and data is a byte array).
I've tried to "interrupt" the call by calling in.close() on another thread, but it has no effect until the internet connection is restored (at which time an exception is thrown).
Is there any way I can prevent a severed internet connection from freezing my program?