use of org.apache.wicket.request.resource.PartWriterCallback in project wicket by apache.
the class FileSystemResource method createResourceResponse.
/**
* Creates a resource response based on the given attributes
*
* @param path
* the path to create the resource response with
* @param attributes
* request attributes
* @return the actual resource response
*/
protected ResourceResponse createResourceResponse(Attributes attributes, Path path) {
try {
if (path == null) {
throw new WicketRuntimeException("Please override #newResourceResponse() and provide a path if using a constructor which doesn't take one as argument.");
}
this.path = new PathModel(path);
long size = getSize();
ResourceResponse resourceResponse = new ResourceResponse();
resourceResponse.setContentType(getMimeType());
resourceResponse.setAcceptRange(ContentRangeType.BYTES);
resourceResponse.setContentLength(size);
if (path.getFileName() != null) {
resourceResponse.setFileName(path.getFileName().toString());
}
RequestCycle cycle = RequestCycle.get();
Long startbyte = cycle.getMetaData(CONTENT_RANGE_STARTBYTE);
Long endbyte = cycle.getMetaData(CONTENT_RANGE_ENDBYTE);
resourceResponse.setWriteCallback(new PartWriterCallback(getInputStream(), size, startbyte, endbyte).setClose(true));
return resourceResponse;
} catch (IOException e) {
throw new WicketRuntimeException("An error occurred while processing the media resource response", e);
}
}
Aggregations