Java Code Examples for org.springframework.http.MediaType#IMAGE_JPEG
The following examples show how to use
org.springframework.http.MediaType#IMAGE_JPEG .
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 |
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 |
/** * 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 |
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: ImagesUtils.java From spring-boot-chatbot with MIT License | 5 votes |
public static MediaType selectMediaTypeForImage(String fileName) { if("jpg".equals(fileName)){ return MediaType.IMAGE_JPEG; }else if("png".equals(fileName)){ return MediaType.IMAGE_PNG; } throw new NullPointerException(); }
Example 5
Source File: ImageWSTest.java From mojito with Apache License 2.0 | 5 votes |
@Test public void testGetMediaTypeFromImageNameJpg() { String imageName = "image1.jpg"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_JPEG; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
Example 6
Source File: ImageWSTest.java From mojito with Apache License 2.0 | 5 votes |
@Test public void testGetMediaTypeFromImageNameJpeg() { String imageName = "image1.jpeg"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_JPEG; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
Example 7
Source File: SpringWebfluxApiExceptionHandlerUtilsTest.java From backstopper with Apache License 2.0 | 5 votes |
@Test public void generateServerResponseForError_works_as_expected() { // given DefaultErrorContractDTO errorContractDtoMock = mock(DefaultErrorContractDTO.class); int statusCode = 400; Collection<ApiError> errors = mock(Collection.class); Throwable ex = mock(Throwable.class); RequestInfoForLogging requestMock = mock(RequestInfoForLogging.class); String expectedSerializedContract = UUID.randomUUID().toString(); doReturn(expectedSerializedContract).when(utilsSpy).serializeErrorContractToString(errorContractDtoMock); MediaType expectedResponseContentType = MediaType.IMAGE_JPEG; doReturn(expectedResponseContentType).when(utilsSpy).getErrorResponseContentType( errorContractDtoMock, statusCode, errors, ex, requestMock ); // when Mono<ServerResponse> resultMono = utilsSpy.generateServerResponseForError( errorContractDtoMock, statusCode, errors, ex, requestMock ); // then verify(utilsSpy).getErrorResponseContentType(errorContractDtoMock, statusCode, errors, ex, requestMock); verify(utilsSpy).serializeErrorContractToString(errorContractDtoMock); ServerResponse result = resultMono.block(); assertThat(result.statusCode().value()).isEqualTo(statusCode); assertThat(result.headers().getContentType()).isEqualTo(expectedResponseContentType); // Yes this is awful. But figuring out how to spit out the ServerResponse's body to something assertable // in this test is also awful. assertThat(Whitebox.getInternalState(result, "entity")).isEqualTo(expectedSerializedContract); }