I can't see a Javascript solution since the Javascript runs in a page and the file being downloaded isn't 'inside' the page. I can't see the Javascript having any control over the download process. I may well be wrong though
I'd look at a
Servlet solution, where the client requests the file to be downloaded from a Servlet rather than requesting the file itself. This allows the Servlet to 'watch' the streams.
If the client cancels the download before it is completed or something else goes wrong, an Exception should be automatically thrown which the Servlet can detect and manage as a 'failed' download situation.
Dave.