public void getRawContent(String contentId, HttpServletResponse response) {
ContentItem contentItem = contentService.createContentItemQuery().id(contentId).singleResult();
if (contentItem == null) {
throw new NotFoundException("No content found with id: " + contentId);
}
if (!contentItem.isContentAvailable()) {
throw new NotFoundException("Raw content not yet available for id: " + contentId);
}
if (!permissionService.canDownloadContent(SecurityUtils.getCurrentUserObject(), contentItem)) {
throw new NotPermittedException("You are not allowed to read the content with id: " + contentId);
}
if (contentItem.getMimeType() != null) {
response.setContentType(contentItem.getMimeType());
}
try (InputStream inputstream = contentService.getContentItemData(contentId)) {
IOUtils.copy(inputstream, response.getOutputStream());
} catch (IOException e) {
throw new InternalServerErrorException("Error while writing raw content data for content: " + contentId, e);
}
}