Search in sources :

Example 1 with ImageQuality

use of alien4cloud.utils.ImageQuality in project alien4cloud by alien4cloud.

the class ImageServlet method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    final String imageId = req.getParameter("id");
    final String quality = req.getParameter("quality");
    final ImageQuality imageQuality;
    if (quality == null) {
        imageQuality = ImageQuality.QUALITY_BEST;
    } else {
        imageQuality = ImageQuality.valueOf(quality);
    }
    final ImageData imageData = this.imageDAO.readImage(imageId, imageQuality);
    if (imageData != null) {
        // Set content type
        resp.setContentType(imageData.getMime());
        // Set content size
        resp.setContentLength(imageData.getData().length);
        // Open the file and output streams
        final OutputStream out = resp.getOutputStream();
        try {
            out.write(imageData.getData());
        } finally {
            out.close();
        }
    } else {
        resp.setStatus(HttpStatus.NOT_FOUND.value());
    }
}
Also used : ImageQuality(alien4cloud.utils.ImageQuality) ImageData(alien4cloud.images.ImageData) OutputStream(java.io.OutputStream)

Aggregations

ImageData (alien4cloud.images.ImageData)1 ImageQuality (alien4cloud.utils.ImageQuality)1 OutputStream (java.io.OutputStream)1