Java Code Examples for org.springframework.util.MimeType#getCharset()

The following examples show how to use org.springframework.util.MimeType#getCharset() . 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: StompHeaderAccessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private String appendPayload(Object payload) {
	if (payload.getClass() != byte[].class) {
		throw new IllegalStateException(
				"Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass()));
	}
	byte[] bytes = (byte[]) payload;
	MimeType mimeType = getContentType();
	String contentType = (mimeType != null ? " " + mimeType.toString() : "");
	if (bytes.length == 0 || mimeType == null || !isReadableContentType()) {
		return contentType;
	}
	Charset charset = mimeType.getCharset();
	charset = (charset != null ? charset : StandardCharsets.UTF_8);
	return (bytes.length < 80) ?
			contentType + " payload=" + new String(bytes, charset) :
			contentType + " payload=" + new String(Arrays.copyOf(bytes, 80), charset) + "...(truncated)";
}
 
Example 2
Source File: StompHeaderAccessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
private String appendPayload(Object payload) {
	if (payload.getClass() != byte[].class) {
		throw new IllegalStateException(
				"Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass()));
	}
	byte[] bytes = (byte[]) payload;
	MimeType mimeType = getContentType();
	String contentType = (mimeType != null ? " " + mimeType.toString() : "");
	if (bytes.length == 0 || mimeType == null || !isReadableContentType()) {
		return contentType;
	}
	Charset charset = mimeType.getCharset();
	charset = (charset != null ? charset : StandardCharsets.UTF_8);
	return (bytes.length < 80) ?
			contentType + " payload=" + new String(bytes, charset) :
			contentType + " payload=" + new String(Arrays.copyOf(bytes, 80), charset) + "...(truncated)";
}
 
Example 3
Source File: StringMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Charset getContentTypeCharset(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		return mimeType.getCharset();
	}
	else {
		return this.defaultCharset;
	}
}
 
Example 4
Source File: MappingJackson2MessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the MIME type from the MessageHeaders, if any
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType contentType) {
	if (contentType != null && (contentType.getCharset() != null)) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 5
Source File: CharSequenceEncoder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Charset getCharset(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		return mimeType.getCharset();
	}
	else {
		return DEFAULT_CHARSET;
	}
}
 
Example 6
Source File: StringDecoder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static Charset getCharset(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		return mimeType.getCharset();
	}
	else {
		return DEFAULT_CHARSET;
	}
}
 
Example 7
Source File: AbstractJackson2Encoder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given mime type.
 * @param mimeType the mime type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 * @since 5.0.5
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		Charset charset = mimeType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 8
Source File: StringMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Charset getContentTypeCharset(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		return mimeType.getCharset();
	}
	else {
		return this.defaultCharset;
	}
}
 
Example 9
Source File: MappingJackson2MessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the MIME type from the MessageHeaders, if any
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType contentType) {
	if (contentType != null && (contentType.getCharset() != null)) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 10
Source File: CharSequenceEncoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Charset getCharset(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		return mimeType.getCharset();
	}
	else {
		return DEFAULT_CHARSET;
	}
}
 
Example 11
Source File: StringDecoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static Charset getCharset(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		return mimeType.getCharset();
	}
	else {
		return DEFAULT_CHARSET;
	}
}
 
Example 12
Source File: AbstractJackson2Encoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given mime type.
 * @param mimeType the mime type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 * @since 5.0.5
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		Charset charset = mimeType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 13
Source File: MessageHeaderAccessor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private Charset getCharset() {
	MimeType contentType = getContentType();
	Charset charset = (contentType != null ? contentType.getCharset() : null);
	return (charset != null ? charset : DEFAULT_CHARSET);
}
 
Example 14
Source File: MessageHeaderAccessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Charset getCharset() {
	MimeType contentType = getContentType();
	Charset charset = (contentType != null ? contentType.getCharset() : null);
	return (charset != null ? charset : DEFAULT_CHARSET);
}