Spring Framework MediaType - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MediaType class.

This code example shows how to use the following methods:isWildcardSubtype, isWildcardType, toString
			wireFeedEncoding = DEFAULT_CHARSET.name();
		} 
		MediaType contentType = outputMessage.getHeaders().getContentType();
		if (contentType != null) {
			Charset wireFeedCharset = Charset.forName(wireFeedEncoding);
			contentType = new MediaType(contentType.getType(), contentType.getSubtype(), wireFeedCharset);
			outputMessage.getHeaders().setContentType(contentType);
		} 
 
		WireFeedOutput feedOutput = new WireFeedOutput();
		try { 
			Writer writer = new OutputStreamWriter(outputMessage.getBody(), wireFeedEncoding);
			feedOutput.output(wireFeed, writer);
		} 
		catch (FeedException ex) {
			throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
		} 
	} 
 
} 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		converter = new ByteArrayHttpMessageConverter();
	} 
 
	@Test
	public void canRead() { 
		assertTrue(converter.canRead(byte[].class, new MediaType("application", "octet-stream")));
	} 
 
	@Test
	public void canWrite() { 
		assertTrue(converter.canWrite(byte[].class, new MediaType("application", "octet-stream")));
		assertTrue(converter.canWrite(byte[].class, MediaType.ALL));
	} 
 
	@Test
	public void read() throws IOException {
		byte[] body = new byte[]{0x1, 0x2};
		MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
		inputMessage.getHeaders().setContentType(new MediaType("application", "octet-stream"));
		byte[] result = converter.read(byte[].class, inputMessage);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isWildcardSubtype, isWildcardType, toString
This code example shows how to use the following methods:
	@SmallTest 
	public void testWriteOverrideRequestedContentType() throws IOException {
		Charset utf8 = Charset.forName("UTF-8");
		MediaType requestedContentType = new MediaType("text", "html");
		MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
		MediaType contentType = new MediaType("text", "plain", utf8);
		outputMessage.getHeaders().setContentType(contentType);
		String body = "H\u00e9llo W\u00f6rld";
		converter.write(body, requestedContentType, outputMessage);
		assertEquals("Invalid result", body, outputMessage.getBodyAsString(utf8));
		assertEquals("Invalid content-type", contentType, outputMessage.getHeaders().getContentType());
		assertEquals("Invalid content-length", body.getBytes(utf8.displayName()).length,
				outputMessage.getHeaders().getContentLength());
		assertFalse("Invalid accept-charset", outputMessage.getHeaders().getAcceptCharset().isEmpty());
	} 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	@Test
	public void read() throws IOException {
		String body = "Hello World";
		Charset charset = Charset.forName("UTF-8");
		MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(charset));
		inputMessage.getHeaders().setContentType(new MediaType("text", "plain", charset));
		String result = converter.read(String.class, inputMessage);
		assertEquals("Invalid result", body, result);
	} 
 
	@Test
	public void writeDefaultCharset() throws IOException {
		Charset iso88591 = Charset.forName("ISO-8859-1");
		MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
		String body = "H\u00e9llo W\u00f6rld";
		converter.write(body, null, outputMessage);
		assertEquals("Invalid result", body, outputMessage.getBodyAsString(iso88591));
		assertEquals("Invalid content-type", new MediaType("text", "plain", iso88591),
				outputMessage.getHeaders().getContentType());
		assertEquals("Invalid content-length", body.getBytes(iso88591).length,
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		XMLUnit.setIgnoreWhitespace(true); 
	} 
 
	@Test 
	public void canRead() { 
		assertTrue(converter.canRead(Feed.class, new MediaType("application", "atom+xml"))); 
		assertTrue(converter.canRead(Feed.class, new MediaType("application", "atom+xml", utf8))); 
	} 
 
	@Test 
	public void canWrite() { 
		assertTrue(converter.canWrite(Feed.class, new MediaType("application", "atom+xml"))); 
		assertTrue(converter.canWrite(Feed.class, new MediaType("application", "atom+xml", Charset.forName("UTF-8")))); 
	} 
 
	@Test 
	public void read() throws IOException { 
		InputStream is = getClass().getResourceAsStream("atom.xml"); 
		MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); 
		inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", utf8)); 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		converter = new ResourceHttpMessageConverter();
	} 
 
	@Test
	public void canRead() { 
		assertTrue(converter.canRead(Resource.class, new MediaType("application", "octet-stream")));
	} 
 
	@Test
	public void canWrite() { 
		assertTrue(converter.canWrite(Resource.class, new MediaType("application", "octet-stream")));
		assertTrue(converter.canWrite(Resource.class, MediaType.ALL));
	} 
 
	@Test
	public void read() throws IOException {
		byte[] body = FileCopyUtils.copyToByteArray(getClass().getResourceAsStream("logo.jpg"));
		MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
		inputMessage.getHeaders().setContentType(MediaType.IMAGE_JPEG);
		converter.read(Resource.class, inputMessage);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		XMLUnit.setIgnoreWhitespace(true); 
	} 
 
	@Test 
	public void canRead() { 
		assertTrue(converter.canRead(Channel.class, new MediaType("application", "rss+xml"))); 
		assertTrue(converter.canRead(Channel.class, new MediaType("application", "rss+xml", utf8))); 
	} 
 
	@Test 
	public void canWrite() { 
		assertTrue(converter.canWrite(Channel.class, new MediaType("application", "rss+xml"))); 
		assertTrue(converter.canWrite(Channel.class, new MediaType("application", "rss+xml", Charset.forName("UTF-8")))); 
	} 
 
	@Test 
	public void read() throws IOException { 
		InputStream is = getClass().getResourceAsStream("rss.xml"); 
		MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); 
		inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", utf8)); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<byte[]> {
 
	/** Creates a new instance of the {@code ByteArrayHttpMessageConverter}. */ 
	public ByteArrayHttpMessageConverter() { 
		super(new MediaType("application", "octet-stream"), MediaType.ALL);
	} 
 
	@Override 
	public boolean supports(Class<?> clazz) {
		return byte[].class.equals(clazz);
	} 
 
	@Override 
	public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException {
		long contentLength = inputMessage.getHeaders().getContentLength();
		ByteArrayOutputStream bos =
				new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);
		StreamUtils.copy(inputMessage.getBody(), bos);
		return bos.toByteArray();
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 * @see Channel 
 */ 
public class RssChannelHttpMessageConverter extends AbstractWireFeedHttpMessageConverter<Channel> {
 
	public RssChannelHttpMessageConverter() { 
		super(new MediaType("application", "rss+xml"));
	} 
 
	@Override 
	protected boolean supports(Class<?> clazz) {
		return Channel.class.isAssignableFrom(clazz);
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework MediaType Methods: