How to tell when a download is completed?

I’ve followed the discussion in this thread:
File Download Discussion
and my application is now able to download a file.

The download happens via a popup window that displays the name of the file and provides a button to download the file.

When the button is clicked, the application happily downloads the file, but the popup window is now empty. If I try to add new content to the window, such as a button to allow the user to close the window, it is not displayed. If I close the window immediately after opening it with the download resource stream the window happily closes but the download terminates (never really starts).

How can I tell when the download is actually completed?

I had hoped to use the InputStream.available method, but the Javadoc says this method always returns a 0 for the InputStream class and the Vaadin DownloadStream class contains an InputStream object rather than implementing or extending InputStream so the available() method is not overridden.

For now, I guess I’ll have to let users click the “X” in the upper right hand corner of the window once the download is done, but I hope there’s a better way.

Thanks in advance for the help.