Java Code Examples for org.springframework.util.MimeTypeUtils#TEXT_PLAIN

The following examples show how to use org.springframework.util.MimeTypeUtils#TEXT_PLAIN . 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: JavaClassMimeTypeUtils.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
/**
 * Convert payload to {@link MimeType} based on the content type on the message.
 * @param payload the payload to convert
 * @param originalContentType content type on the message
 * @return converted {@link MimeType}
 */
public static MimeType mimeTypeFromObject(Object payload,
		String originalContentType) {
	Assert.notNull(payload, "payload object cannot be null.");
	if (payload instanceof byte[]) {
		return MimeTypeUtils.APPLICATION_OCTET_STREAM;
	}
	if (payload instanceof String) {
		return MimeTypeUtils.APPLICATION_JSON_VALUE.equals(originalContentType)
				? MimeTypeUtils.APPLICATION_JSON : MimeTypeUtils.TEXT_PLAIN;
	}
	String className = payload.getClass().getName();
	MimeType mimeType = mimeTypesCache.get(className);
	if (mimeType == null) {
		String modifiedClassName = className;
		if (payload.getClass().isArray()) {
			// Need to remove trailing ';' for an object array, e.g.
			// "[Ljava.lang.String;" or multi-dimensional
			// "[[[Ljava.lang.String;"
			if (modifiedClassName.endsWith(";")) {
				modifiedClassName = modifiedClassName.substring(0,
						modifiedClassName.length() - 1);
			}
			// Wrap in quotes to handle the illegal '[' character
			modifiedClassName = "\"" + modifiedClassName + "\"";
		}
		mimeType = MimeType
				.valueOf("application/x-java-object;type=" + modifiedClassName);
		mimeTypesCache.put(className, mimeType);
	}
	return mimeType;
}
 
Example 2
Source File: MessageConverterTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public TestMessageConverter() {
	super(MimeTypeUtils.TEXT_PLAIN);
}
 
Example 3
Source File: MessageConverterTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
public TestMessageConverter() {
	super(MimeTypeUtils.TEXT_PLAIN);
}
 
Example 4
Source File: AbstractMessageConverterTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public TestMessageConverter() {
	super(MimeTypeUtils.TEXT_PLAIN);
}
 
Example 5
Source File: MessageConverterTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public TestMessageConverter() {
	super(MimeTypeUtils.TEXT_PLAIN);
}