Search in sources :

Example 1 with PartWriterCallback

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);
    }
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) PartWriterCallback(org.apache.wicket.request.resource.PartWriterCallback)

Aggregations

IOException (java.io.IOException)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 PartWriterCallback (org.apache.wicket.request.resource.PartWriterCallback)1