You could do just like DownloadLink
does and create a FileResourceStream
from the zipped file. Then, just change the target of the current request cycle:
Button downloadLogButton = new Button("downloadlogbutton") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
// Some utility class I made that zips files
LogUtility util = new LogUtility();
util.zipLogFiles("sample", logs);
IResourceStream resourceStream = new FileResourceStream(
new org.apache.wicket.util.file.File(someFile)); // Use whatever file you need here
IRequestTarget t = new ResourceStreamRequestTarget(stream){
@Override
public String getFileName() {
return "filename.zip";
}
}
getRequestCycle().setRequestTarget(t);
}
};
If you wanted to delete the file after the download, you could override IRequestTarget#respond(RequestCycle)
like this:
@Override
public void respond(RequestCycle requestCycle) {
super.respond(requestCycle);
// Delete the file
((FileResourceStream)getResourceStream()).getFile().delete();
}
The following related question could also be useful: How to use Wicket's DownloadLink with a file generated on the fly?.