Opening a streamresource in Vaadin 7

Hi,

In our system there are a few places where user can download content either to their own computer or to some remote host in our computing environment. Before initiating the actual download user is presented with a window where they can choose the destination (from a drop-down menu) and then start the download from a button. In Vaadin 6 this was handled by adding a clicklistener to that button and in its implementation, depending on the download location, create a new streamresource and use getMainWindow.open(resource…) to download the content or do some steps to transfer that content to a remote host. In Vaadin 7 that open(Resource…) -method is deprecated and open method with String parameter should be used instead.

Creating a temporary file from the content is not feasible since the content can be several gigabytes in size. Also, using a link or creating a FileDownloader and using its extend method to add it to the button and to download the content is not good for this situation since pushing the button or link starts download immediately and it is not possible to check the location and do different things depending on that selection. Also, having several download-buttons is not perhaps the best user experience solution.

Is there a good way to handle these kind of situations using Vaadin 7? Or maybe I have missed some obvious solution. Right now I could go on using that deprecated open-method, but eventually that needs to be changed.

Thanks!

Mikko “Mikko” Jokinen

You can stream your byte output in a button.

What I have done is to create a callback in FileDownloader so it is changed when the user clicks the button.

The callback will return an InputStream. You can use PipedInputStream to pipe the output from another thread, so it will not take out disk space or memory. I used ZipOutputStream to zip the payload on the fly to reduce bandwidth.

https://gist.github.com/anonymous/5487979

It’s more code than what I would like but it works.

Ray