Java Code Examples for org.springframework.http.MediaType#IMAGE_GIF

The following examples show how to use org.springframework.http.MediaType#IMAGE_GIF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttachmentApiController.java    From onboard with Apache License 2.0 7 votes vote down vote up
private MediaType getContentType(String contentType) {
    if (contentType.equalsIgnoreCase(MediaType.IMAGE_GIF_VALUE)) {
        return MediaType.IMAGE_GIF;
    } else if (contentType.equalsIgnoreCase(MediaType.IMAGE_PNG_VALUE)) {
        return MediaType.IMAGE_PNG;
    } else if (contentType.equalsIgnoreCase(MediaType.IMAGE_JPEG_VALUE)) {
        return MediaType.IMAGE_JPEG;
    } else if (contentType.equalsIgnoreCase(MediaType.TEXT_PLAIN_VALUE)) {
        return MediaType.TEXT_PLAIN;
    } else if (contentType.equalsIgnoreCase(MediaType.TEXT_XML_VALUE)) {
        return MediaType.TEXT_XML;
    } else if (contentType.equalsIgnoreCase(MediaType.TEXT_HTML_VALUE)) {
        return MediaType.TEXT_HTML;
    }
    return MediaType.APPLICATION_OCTET_STREAM;
}
 
Example 2
Source File: ImageWS.java    From mojito with Apache License 2.0 6 votes vote down vote up
/**
 * Get the media type of an image based on its extension. Supported types
 * are JPEG, PNG and GIF. If there is no match based on the extension,
 * MediaType.APPLICATION_OCTET_STREAM is returned.
 *
 * @param imageName an image name
 * @return the media type of the image
 */
MediaType getMediaTypeFromImageName(String imageName) {
    MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;

    String fileExtension = FilenameUtils.getExtension(imageName).toLowerCase();

    switch (fileExtension) {
        case "jpeg":
        case "jpg":
            mediaType = MediaType.IMAGE_JPEG;
            break;
        case "png":
            mediaType = MediaType.IMAGE_PNG;
            break;
        case "gif":
            mediaType = MediaType.IMAGE_GIF;
            break;
    }

    return mediaType;
}
 
Example 3
Source File: AttachmentApi.java    From onboard with Apache License 2.0 6 votes vote down vote up
private MediaType getContentType(String contentType) {
    if (contentType.equalsIgnoreCase(MediaType.IMAGE_GIF_VALUE)) {
        return MediaType.IMAGE_GIF;
    } else if (contentType.equalsIgnoreCase(MediaType.IMAGE_PNG_VALUE)) {
        return MediaType.IMAGE_PNG;
    } else if (contentType.equalsIgnoreCase(MediaType.IMAGE_JPEG_VALUE)) {
        return MediaType.IMAGE_JPEG;
    } else if (contentType.equalsIgnoreCase(MediaType.TEXT_PLAIN_VALUE)) {
        return MediaType.TEXT_PLAIN;
    } else if (contentType.equalsIgnoreCase(MediaType.TEXT_XML_VALUE)) {
        return MediaType.TEXT_XML;
    } else if (contentType.equalsIgnoreCase(MediaType.TEXT_HTML_VALUE)) {
        return MediaType.TEXT_HTML;
    }
    return MediaType.APPLICATION_OCTET_STREAM;
}
 
Example 4
Source File: ImageWSTest.java    From mojito with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMediaTypeFromImageNameGif() {
    String imageName = "image1.gif";
    ImageWS instance = new ImageWS();
    MediaType expResult = MediaType.IMAGE_GIF;
    MediaType result = instance.getMediaTypeFromImageName(imageName);
    assertEquals(expResult, result);
}
 
Example 5
Source File: MediaTypeTest.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void toStringTest() {
    MediaType mediaType = MediaType.IMAGE_GIF;

    assertThat(mediaType.toString(), equalTo("image/gif"));
}