Example usage for org.springframework.http MediaType IMAGE_GIF

List of usage examples for org.springframework.http MediaType IMAGE_GIF

Introduction

In this page you can find the example usage for org.springframework.http MediaType IMAGE_GIF.

Prototype

MediaType IMAGE_GIF

To view the source code for org.springframework.http MediaType IMAGE_GIF.

Click Source Link

Document

Public constant media type for image/gif .

Usage

From source file:com.example.securelogin.app.account.AccountController.java

@RequestMapping(value = "/image")
@ResponseBody/*from   w w w  .j  a va 2s .c o  m*/
public ResponseEntity<byte[]> showImage(@AuthenticationPrincipal LoggedInUser userDetails) throws IOException {
    AccountImage userImage = accountSharedService.getImage(userDetails.getUsername());
    HttpHeaders headers = new HttpHeaders();
    if (userImage.getExtension().equalsIgnoreCase("png")) {
        headers.setContentType(MediaType.IMAGE_PNG);
    } else if (userImage.getExtension().equalsIgnoreCase("gif")) {
        headers.setContentType(MediaType.IMAGE_GIF);
    } else if (userImage.getExtension().equalsIgnoreCase("jpg")) {
        headers.setContentType(MediaType.IMAGE_JPEG);
    }
    return new ResponseEntity<byte[]>(IOUtils.toByteArray(userImage.getBody()), headers, HttpStatus.OK);
}

From source file:gr.cti.android.experimentation.Application.java

@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return servletContainer -> ((TomcatEmbeddedServletContainerFactory) servletContainer)
            .addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
                AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
                httpProtocol.setCompression("on");
                httpProtocol.setCompressionMinSize(256);
                String mimeTypes = httpProtocol.getCompressableMimeTypes();
                String mimeTypesWithJson = mimeTypes + "," + MediaType.APPLICATION_JSON_VALUE + ","
                        + MediaType.IMAGE_PNG + "," + MediaType.IMAGE_GIF + "," + MediaType.IMAGE_JPEG + ","
                        + "application/javascript" + "," + "text/css";
                httpProtocol.setCompressableMimeTypes(mimeTypesWithJson);
            });/*from  www .j av  a  2s  .  c  om*/
}

From source file:org.openschedule.api.impl.AbstractOpenSchedulApiBinding.java

/**
 * Returns a {@link ByteArrayHttpMessageConverter} to be used by the internal {@link RestTemplate} when consuming image or other binary resources.
 * By default, the message converter supports "image/jpeg", "image/gif", and "image/png" media types.
 * Override to customize the message converter (for example, to set supported media types).
 * To remove/replace this or any of the other message converters that are registered by default, override the getMessageConverters() method instead.    
 *//*from  w  ww. j  av  a 2s  . c om*/
protected ByteArrayHttpMessageConverter getByteArrayMessageConverter() {
    ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
    converter.setSupportedMediaTypes(
            Arrays.asList(MediaType.IMAGE_JPEG, MediaType.IMAGE_GIF, MediaType.IMAGE_PNG));
    return converter;
}

From source file:com.aspose.showcase.qrcodegen.web.api.controller.QRCodeManagementController.java

private ImageFormatDTO getRequestedImageFormat(HttpHeaders responseHeaders, String acceptHeaderValue,
        String format) {//from  w  ww .  j a va  2  s  . c  om

    ImageFormatDTO generatedImageFormat = new ImageFormatDTO(ImageFormat.getPng(), MediaType.IMAGE_PNG,
            com.aspose.barcode.BarCodeImageFormat.Png);
    responseHeaders.setContentType(MediaType.IMAGE_PNG);

    if (StringUtils.isBlank(acceptHeaderValue) && StringUtils.isBlank(format)) {
        return new ImageFormatDTO(ImageFormat.getPng(), MediaType.IMAGE_PNG,
                com.aspose.barcode.BarCodeImageFormat.Png);
    }

    String requestedFormat = "Png";

    if (StringUtils.isNotBlank(format)) {
        requestedFormat = format.trim();

    } else if (StringUtils.isNotBlank(acceptHeaderValue)) {
        requestedFormat = StringUtils.removeStartIgnoreCase(acceptHeaderValue.trim(), "image/");
    }

    if ("Jpeg".equalsIgnoreCase(requestedFormat)) {

        generatedImageFormat = new ImageFormatDTO(ImageFormat.getJpeg(), MediaType.IMAGE_JPEG,
                com.aspose.barcode.BarCodeImageFormat.Jpeg);
        responseHeaders.setContentType(MediaType.IMAGE_JPEG);

    } else if ("Png".equalsIgnoreCase(requestedFormat)) {

        generatedImageFormat = new ImageFormatDTO(ImageFormat.getPng(), MediaType.IMAGE_PNG,
                com.aspose.barcode.BarCodeImageFormat.Png);
        responseHeaders.setContentType(MediaType.IMAGE_PNG);

    } else if ("Gif".equalsIgnoreCase(requestedFormat)) {

        generatedImageFormat = new ImageFormatDTO(ImageFormat.getGif(), MediaType.IMAGE_GIF,
                com.aspose.barcode.BarCodeImageFormat.Gif);
        responseHeaders.setContentType(MediaType.IMAGE_GIF);

    } else if ("Tiff".equalsIgnoreCase(requestedFormat)) {

        generatedImageFormat = new ImageFormatDTO(ImageFormat.getTiff(),
                new MediaType(MEDIATYPE_IMAGE, MEDIATYPE_IMAGE_TIFF),
                com.aspose.barcode.BarCodeImageFormat.Tiff);
        responseHeaders.setContentType(new MediaType("image", MEDIATYPE_IMAGE_TIFF));

    } else if ("Bmp".equalsIgnoreCase(requestedFormat)) {

        generatedImageFormat = new ImageFormatDTO(ImageFormat.getBmp(),
                new MediaType(MEDIATYPE_IMAGE, MEDIATYPE_IMAGE_BMP), com.aspose.barcode.BarCodeImageFormat.Bmp);
        responseHeaders.setContentType(new MediaType("image", MEDIATYPE_IMAGE_BMP));

    } else {

        generatedImageFormat = new ImageFormatDTO(ImageFormat.getPng(), MediaType.IMAGE_PNG,
                com.aspose.barcode.BarCodeImageFormat.Png);
        responseHeaders.setContentType(MediaType.IMAGE_PNG);
    }

    return generatedImageFormat;
}

From source file:it.smartcommunitylab.climb.contextstore.controller.ChildController.java

@RequestMapping(value = "/api/image/download/{imageType}/{ownerId}/{objectId}", method = RequestMethod.GET)
public @ResponseBody HttpEntity<byte[]> downloadImage(@PathVariable String imageType,
        @PathVariable String ownerId, @PathVariable String objectId, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Criteria criteria = Criteria.where("objectId").is(objectId);
    Child child = storage.findOneData(Child.class, criteria, ownerId);
    if (!validateAuthorizationByExp(ownerId, child.getInstituteId(), child.getSchoolId(), null, "ALL",
            request)) {/*from w  w w  . ja  v a  2s  . co  m*/
        throw new UnauthorizedException("Unauthorized Exception: token not valid");
    }
    String name = objectId + "." + imageType;
    String path = imageUploadDir + "/" + name;
    if (logger.isInfoEnabled()) {
        logger.info("downloadImage:" + name);
    }
    FileInputStream in = new FileInputStream(new File(path));
    byte[] image = IOUtils.toByteArray(in);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);
    if (imageType.toLowerCase().equals("png")) {
        headers.setContentType(MediaType.IMAGE_PNG);
    } else if (imageType.toLowerCase().equals("gif")) {
        headers.setContentType(MediaType.IMAGE_GIF);
    } else if (imageType.toLowerCase().equals("jpg")) {
        headers.setContentType(MediaType.IMAGE_JPEG);
    } else if (imageType.toLowerCase().equals("jpeg")) {
        headers.setContentType(MediaType.IMAGE_JPEG);
    }
    headers.setContentLength(image.length);
    return new HttpEntity<byte[]>(image, headers);
}

From source file:it.smartcommunitylab.climb.domain.controller.ChildController.java

@RequestMapping(value = "/api/child/image/download/{imageType}/{ownerId}/{objectId}", method = RequestMethod.GET)
public @ResponseBody HttpEntity<byte[]> downloadImage(@PathVariable String imageType,
        @PathVariable String ownerId, @PathVariable String objectId, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Criteria criteria = Criteria.where("objectId").is(objectId);
    Child child = storage.findOneData(Child.class, criteria, ownerId);
    if (child == null) {
        throw new EntityNotFoundException("child not found");
    }/* ww w  . ja  va  2  s  . c  om*/
    if (!validateAuthorization(ownerId, child.getInstituteId(), child.getSchoolId(), null, null,
            Const.AUTH_RES_Image, Const.AUTH_ACTION_READ, request)) {
        throw new UnauthorizedException("Unauthorized Exception: token not valid");
    }
    String name = objectId + "." + imageType;
    String path = imageUploadDir + "/" + name;
    if (logger.isInfoEnabled()) {
        logger.info("downloadImage:" + name);
    }
    FileInputStream in = new FileInputStream(new File(path));
    byte[] image = IOUtils.toByteArray(in);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);
    if (imageType.toLowerCase().equals("png")) {
        headers.setContentType(MediaType.IMAGE_PNG);
    } else if (imageType.toLowerCase().equals("gif")) {
        headers.setContentType(MediaType.IMAGE_GIF);
    } else if (imageType.toLowerCase().equals("jpg")) {
        headers.setContentType(MediaType.IMAGE_JPEG);
    } else if (imageType.toLowerCase().equals("jpeg")) {
        headers.setContentType(MediaType.IMAGE_JPEG);
    }
    headers.setContentLength(image.length);
    return new HttpEntity<byte[]>(image, headers);
}