com.sun.net.httpserver freezes when user cancel downloading while server transfering file
This is piece of implementation of java web-server (based on com.sun.net.httpserver) which serves static file downloading.
while ((count = fs.read(buffer)) > 0) {
try {
output.write(buffer, 0, count);
output.flush();
} catch (IOException e) {
System.out.print(e.getMessage() + "\n");
}
}
If user click Cancel in Save As dialog window while aforementioned piece of code still works the server freezes without throwing exception (I expect Broken Pipe exception). Any suggestions on how to avoid freeze?