private static Charset getCharset(@Nullable MimeType mimeType) { if (mimeType != null && mimeType.getCharset() != null) { return mimeType.getCharset(); } else { return DEFAULT_CHARSET; } }
private Charset getContentTypeCharset(@Nullable MimeType mimeType) { if (mimeType != null && mimeType.getCharset() != null) { return mimeType.getCharset(); } else { return this.defaultCharset; } }
private Charset getCharset(@Nullable MimeType mimeType) { if (mimeType != null && mimeType.getCharset() != null) { return mimeType.getCharset(); } else { return DEFAULT_CHARSET; } }
private static Charset getCharset(@Nullable MimeType mimeType) { if (mimeType != null && mimeType.getCharset() != null) { return mimeType.getCharset(); } else { return DEFAULT_CHARSET; } }
private Charset getCharset(@Nullable MimeType mimeType) { if (mimeType != null && mimeType.getCharset() != null) { return mimeType.getCharset(); } else { return DEFAULT_CHARSET; } }
private Charset getCharset() { MimeType contentType = getContentType(); Charset charset = (contentType != null ? contentType.getCharset() : null); return (charset != null ? charset : DEFAULT_CHARSET); }
/** * Determine if the parameters in this {@code MimeType} and the supplied * {@code MimeType} are equal, performing case-insensitive comparisons * for {@link Charset Charsets}. * @since 4.2 */ private boolean parametersAreEqual(MimeType other) { if (this.parameters.size() != other.parameters.size()) { return false; } for (Map.Entry<String, String> entry : this.parameters.entrySet()) { String key = entry.getKey(); if (!other.parameters.containsKey(key)) { return false; } if (PARAM_CHARSET.equals(key)) { if (!ObjectUtils.nullSafeEquals(getCharset(), other.getCharset())) { return false; } } else if (!ObjectUtils.nullSafeEquals(entry.getValue(), other.parameters.get(key))) { return false; } } return true; }
/** * 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; }
/** * 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; }
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)"; }
/** * Determine if the parameters in this {@code MimeType} and the supplied * {@code MimeType} are equal, performing case-insensitive comparisons * for {@link Charset Charsets}. * @since 4.2 */ private boolean parametersAreEqual(MimeType other) { if (this.parameters.size() != other.parameters.size()) { return false; } for (Map.Entry<String, String> entry : this.parameters.entrySet()) { String key = entry.getKey(); if (!other.parameters.containsKey(key)) { return false; } if (PARAM_CHARSET.equals(key)) { if (!ObjectUtils.nullSafeEquals(getCharset(), other.getCharset())) { return false; } } else if (!ObjectUtils.nullSafeEquals(entry.getValue(), other.parameters.get(key))) { return false; } } return true; }
/** * 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; }
Charset thisCharset = getCharset(); Charset otherCharset = other.getCharset(); if (thisCharset != otherCharset) { if (thisCharset == null) {
Charset thisCharset = getCharset(); Charset otherCharset = other.getCharset(); if (thisCharset != otherCharset) { if (thisCharset == null) {
@Test public void parseCharset() { String s = "text/html; charset=iso-8859-1"; MimeType mimeType = MimeType.valueOf(s); assertEquals("Invalid type", "text", mimeType.getType()); assertEquals("Invalid subtype", "html", mimeType.getSubtype()); assertEquals("Invalid charset", StandardCharsets.ISO_8859_1, mimeType.getCharset()); }
@Test public void parseQuotedCharset() { String s = "application/xml;charset=\"utf-8\""; MimeType mimeType = MimeType.valueOf(s); assertEquals("Invalid type", "application", mimeType.getType()); assertEquals("Invalid subtype", "xml", mimeType.getSubtype()); assertEquals("Invalid charset", StandardCharsets.UTF_8, mimeType.getCharset()); }
@Test public void parseQuotedSeparator() { String s = "application/xop+xml;charset=utf-8;type=\"application/soap+xml;action=\\\"http://x.y.z\\\"\""; MimeType mimeType = MimeType.valueOf(s); assertEquals("Invalid type", "application", mimeType.getType()); assertEquals("Invalid subtype", "xop+xml", mimeType.getSubtype()); assertEquals("Invalid charset", StandardCharsets.UTF_8, mimeType.getCharset()); assertEquals("\"application/soap+xml;action=\\\"http://x.y.z\\\"\"", mimeType.getParameter("type")); }
private Charset getContentTypeCharset(@Nullable MimeType mimeType) { if (mimeType != null && mimeType.getCharset() != null) { return mimeType.getCharset(); } else { return this.defaultCharset; } }
private Charset getCharset() { MimeType contentType = getContentType(); Charset charset = (contentType != null ? contentType.getCharset() : null); return (charset != null ? charset : DEFAULT_CHARSET); }
/** * 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; }