Example usage for org.springframework.http MediaType IMAGE_PNG

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

Introduction

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

Prototype

MediaType IMAGE_PNG

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

Click Source Link

Document

Public constant media type for image/png .

Usage

From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java

private static void validateFile(MultipartFile file) throws IOException {
    String contentType = file.getContentType();
    if (!contentType.equals(MediaType.IMAGE_JPEG.toString())
            && !contentType.equals(MediaType.IMAGE_PNG.toString()))
        throw new IOException("Invalid media type");
}

From source file:am.ik.categolj2.api.MediaTypeResolverTest.java

@Test
public void testResolve() {
    Map<String, MediaType> map = new HashMap<>();
    map.put("png", MediaType.IMAGE_PNG);
    MediaTypeResolver resolver = new MediaTypeResolver(map);

    assertThat(resolver.resolveFromExtension("png"), is(MediaType.IMAGE_PNG));
    assertThat(resolver.resolveFromExtension("PNG"), is(MediaType.IMAGE_PNG));
    assertThat(resolver.resolveFromExtension("hoge"), is(MediaType.APPLICATION_OCTET_STREAM));
}

From source file:capital.scalable.restdocs.response.BinaryReplacementContentModifierTest.java

@Test
public void testModifyContentWithPng() {
    testModifyContent(MediaType.IMAGE_PNG);
}

From source file:io.github.azige.bbs.web.controller.AvatarController.java

@RequestMapping("/avatar/{id}")
public ResponseEntity<byte[]> avatarResource(@PathVariable Long id) throws IOException {
    return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(IOUtils
            .toByteArray(AvatarController.class.getResourceAsStream("/io/github/azige/bbs/res/haruna.png")));
}

From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java

private static byte[] convertToArray(BufferedImage image, String contentType) throws IOException {
    byte[] imageInByte;

    String typeName = "jpg";
    if (contentType.equals(MediaType.IMAGE_PNG))
        typeName = "png";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, typeName, baos);
    baos.flush();//from  w  ww .  j  a v a 2 s.  c om
    imageInByte = baos.toByteArray();
    baos.close();

    return imageInByte;
}

From source file:am.ik.categolj2.api.MediaTypeResolverTest.java

@Test
public void testResolveFromFileName() {
    Map<String, MediaType> map = new HashMap<>();
    map.put("png", MediaType.IMAGE_PNG);
    MediaTypeResolver resolver = new MediaTypeResolver(map);

    assertThat(resolver.resolveFromFilename("hoge.png"), is(MediaType.IMAGE_PNG));
    assertThat(resolver.resolveFromFilename("foo.PNG"), is(MediaType.IMAGE_PNG));
    assertThat(resolver.resolveFromFilename("bar.hoge"), is(MediaType.APPLICATION_OCTET_STREAM));
}

From source file:com.github.spring.example.ImageService.java

@Cacheable("qr-code-cache")
public byte[] generateQRCode(String text, int width, int height) throws WriterException, IOException {

    Assert.hasText(text);/* ww  w  .  j  av  a2s  .c  om*/
    Assert.isTrue(width > 0);
    Assert.isTrue(height > 0);

    LOGGER.info("Will generate image  text=[{}], width=[{}], height=[{}]", text, width, height);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BitMatrix matrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height);
    MatrixToImageWriter.writeToStream(matrix, MediaType.IMAGE_PNG.getSubtype(), baos,
            new MatrixToImageConfig());
    return baos.toByteArray();
}

From source file:controllers.ImageController.java

@RequestMapping("/")
public ResponseEntity<byte[]> getImage(@RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "id", required = false) String id) throws IOException {
    File file = new File("/usr/local/seller/preview/" + id + "/" + name);
    if (!file.exists()) {
        return null;
    }/*w  w w  .  j a  v  a  2s . c  o m*/
    InputStream in = new FileInputStream(file);
    //new File("/usr/local/seller/preview/"+id+"/"+name).;
    //servletContext.getResourceAsStream("/usr/local/seller/preview/"+id+"/"+name);

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);

    return new ResponseEntity<>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED);
}

From source file:com.abixen.platform.core.controller.common.ImageLibraryController.java

@RequestMapping(value = "/{fileName}/", method = RequestMethod.GET)
public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws IOException {

    log.debug("fileName: " + fileName);

    InputStream in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory()
            + "/layout-miniature/" + fileName);

    byte[] b = IOUtils.toByteArray(in);

    in.close();/*from   ww w.  j  a  v  a 2s . c  om*/

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);

    return new ResponseEntity<byte[]>(b, headers, HttpStatus.CREATED);
}

From source file:com.abixen.platform.core.interfaces.web.common.ImageLibraryController.java

@RequestMapping(value = "layout/{fileName}/", method = RequestMethod.GET)
public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws IOException {

    log.debug("fileName: " + fileName);

    InputStream in;/*from  w ww  . j a v  a2s. c  om*/
    try {
        in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory()
                + "/layout-miniature/" + fileName);
    } catch (FileNotFoundException e) {
        in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory()
                + "/layout-miniature/default-layout-icon.png");
    }
    byte[] b = IOUtils.toByteArray(in);

    in.close();

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);

    return new ResponseEntity<byte[]>(b, headers, HttpStatus.CREATED);
}