use of org.xwiki.container.Response in project xwiki-platform by xwiki.
the class AbstractServletResourceReferenceHandler method serveResource.
/**
* Sends back the specified resource.
*
* @param resourceReference the reference of the requested resource
* @param rawResourceStream the resource stream used to read the resource
* @throws ResourceReferenceHandlerException if it fails to read the resource
*/
private void serveResource(R resourceReference, InputStream rawResourceStream) throws ResourceReferenceHandlerException {
InputStream resourceStream = rawResourceStream;
String resourceName = getResourceName(resourceReference);
// stream, in which case it will mark & reset the stream).
if (!resourceStream.markSupported()) {
resourceStream = new BufferedInputStream(resourceStream);
}
try {
Response response = this.container.getResponse();
setResponseHeaders(response, resourceReference);
response.setContentType(TikaUtils.detect(resourceStream, resourceName));
IOUtils.copy(resourceStream, response.getOutputStream());
} catch (Exception e) {
throw new ResourceReferenceHandlerException(String.format("Failed to read resource [%s]", resourceName), e);
} finally {
IOUtils.closeQuietly(resourceStream);
}
}
Aggregations