use of org.apache.wicket.util.resource.IResourceStream in project midpoint by Evolveum.
the class AjaxDownloadBehaviorFromStream method onRequest.
public void onRequest() {
final InputStream byteStream = initStream();
if (byteStream == null) {
return;
}
IResourceStream resourceStream = new AbstractResourceStream() {
@Override
public String getContentType() {
return contentType;
}
@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
return byteStream;
}
@Override
public void close() throws IOException {
byteStream.close();
}
};
ResourceStreamRequestHandler reqHandler = new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
super.respond(requestCycle);
}
}.setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ONE_SECOND);
if (StringUtils.isNotEmpty(getFileName())) {
reqHandler.setFileName(getFileName());
}
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(reqHandler);
}
use of org.apache.wicket.util.resource.IResourceStream in project midpoint by Evolveum.
the class AjaxDownloadBehaviorFromFile method onRequest.
public void onRequest() {
final File file = initFile();
IResourceStream resourceStream = new FileResourceStream(new File(file));
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
try {
super.respond(requestCycle);
} finally {
if (removeFile) {
LOGGER.debug("Removing file '{}'.", new Object[] { file.getAbsolutePath() });
Files.remove(file);
}
}
}
}.setFileName(file.getName()).setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ONE_SECOND));
}
Aggregations