Spring Framework MimeType - 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 MimeType 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
This code example shows how to use the following methods:isWildcardSubtype, isWildcardType, toString
This code example shows how to use the following methods:
	public StringMessageConverter() { 
		this(Charset.forName("UTF-8"));
	} 
 
	public StringMessageConverter(Charset defaultCharset) {
		super(new MimeType("text", "plain", defaultCharset));
		this.defaultCharset = defaultCharset;
	} 
 
 
	@Override 
	protected boolean supports(Class<?> clazz) {
		return String.class.equals(clazz);
	} 
 
	@Override 
	public Object convertFromInternal(Message<?> message, Class<?> targetClass) {
		Charset charset = getContentTypeCharset(getMimeType(message.getHeaders()));
		Object payload = message.getPayload();
		return (payload instanceof String) ? payload : new String((byte[]) payload, charset);
7
CodeRank
This code example shows how to use the following methods:
import org.springframework.messaging.handler.annotation.MessageMapping; 
import org.springframework.messaging.handler.annotation.SendTo; 
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeMapping; 
import org.springframework.messaging.support.MessageBuilder; 
import org.springframework.messaging.support.MessageHeaderAccessor; 
import org.springframework.util.MimeType;
 
import static org.junit.Assert.*; 
import static org.mockito.BDDMockito.*; 
 
/** 
 * Test fixture for {@link SubscriptionMethodReturnValueHandler}. 
 * 
 * @author Rossen Stoyanchev 
 */ 
public class SubscriptionMethodReturnValueHandlerTests { 
 
	public static final MimeType MIME_TYPE = new MimeType("text", "plain", Charset.forName("UTF-8"));
6
CodeRank
This code example shows how to use the following methods:toString
	public String toString() { 
		StringBuilder builder = new StringBuilder(); 
		if (isNegated) { 
			builder.append('!'); 
		} 
		builder.append(mediaType.toString()); 
		return builder.toString(); 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getCharSet
 
	@Override 
	protected Long getContentLength(Object obj, MediaType contentType) {
		String value = this.conversionService.convert(obj, String.class);
		return this.stringHttpMessageConverter.getContentLength(value, contentType);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getCharSet
	protected List<Charset> getAcceptedCharsets() {
		return this.availableCharsets;
	} 
 
	private Charset getContentTypeCharset(MediaType contentType) {
		if (contentType != null && contentType.getCharSet() != null) {
			return contentType.getCharSet();
		} 
		else { 
			return this.defaultCharset;
		} 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:getCharSet
			throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
		} 
	} 
 
	private void setCharset(MediaType contentType, Marshaller marshaller) throws PropertyException {
		if (contentType != null && contentType.getCharSet() != null) {
			marshaller.setProperty(Marshaller.JAXB_ENCODING, contentType.getCharSet().name());
		} 
	} 
 
 
	private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
		@Override 
		public InputSource resolveEntity(String publicId, String systemId) { 
			return new InputSource(new StringReader("")); 
		} 
	}; 
 
} 
5
CodeRank
This code example shows how to use the following methods:equals
	protected MediaType handleNoMatch(NativeWebRequest webRequest, String extension) 
			throws HttpMediaTypeNotAcceptableException { 
 
		if (this.useJaf) { 
			MediaType jafMediaType = JafMediaTypeFactory.getMediaType("file." + extension); 
			if (jafMediaType != null && !MediaType.APPLICATION_OCTET_STREAM.equals(jafMediaType)) { 
				return jafMediaType; 
			} 
		} 
		if (!this.ignoreUnknownExtensions) { 
			throw new HttpMediaTypeNotAcceptableException(getAllMediaTypes()); 
		} 
		return null; 
	} 
 
 
	/** 
	 * Inner class to avoid hard-coded dependency on JAF. 
	 */ 
	private static class JafMediaTypeFactory { 
5
CodeRank
This code example shows how to use the following methods:getCharSet
	/** 
	 * Set the "X-Protobuf-*" HTTP headers when responding with a message of 
	 * content type "application/x-protobuf" 
	 * <p><b>Note:</b> <code>outputMessage.getBody()</code> should not have been called 
	 * before because it writes HTTP headers (making them read only).</p> 
	 */ 
	private void setProtoHeader(HttpOutputMessage response, Message message) { 
		response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); 
		response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); 
	} 
 
	@Override 
	protected MediaType getDefaultContentType(Message message) { 
		return PROTOBUF; 
	} 
 
} 
5
CodeRank
See Code Examples for Spring Framework MimeType Methods: