be.personify.iam.frontend.wicket.util.CustomDownloadLink Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of personify-frontend Show documentation
Show all versions of personify-frontend Show documentation
frontend library for different usages
package be.personify.iam.frontend.wicket.util;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.wicket.markup.html.link.DownloadLink;
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
import org.apache.wicket.util.resource.FileResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
public class CustomDownloadLink extends DownloadLink{
private static final long serialVersionUID = -5779766712283542869L;
private byte[] bytes = null;
private String fileName = null;
public CustomDownloadLink(String id, byte[] bytes, String fileName ) {
super(id, new File(""));
this.bytes = bytes;
this.fileName = fileName;
}
@Override
public void onClick() {
File downloadFile = new File(fileName);
try {
FileUtils.writeByteArrayToFile(downloadFile, bytes);
}
catch (IOException e) {
e.printStackTrace();
}
IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(downloadFile));
getRequestCycle().scheduleRequestHandlerAfterCurrent
(new ResourceStreamRequestHandler(resourceStream).
setFileName(downloadFile.getName()));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy