/** * Return the character set, as indicated by a {@code charset} parameter, if any. * @return the character set, or {@code null} if not available * @since 4.3 */ @Nullable public Charset getCharset() { String charset = getParameter(PARAM_CHARSET); return (charset != null ? Charset.forName(unquote(charset)) : null); }
/** * Return the character set, as indicated by a {@code charset} parameter, if any. * @return the character set, or {@code null} if not available * @since 4.3 */ @Nullable public Charset getCharset() { String charset = getParameter(PARAM_CHARSET); return (charset != null ? Charset.forName(unquote(charset)) : null); }
@Test // SPR-16630 public void parseMimeTypeWithSpacesAroundEquals() { MimeType mimeType = MimeTypeUtils.parseMimeType("multipart/x-mixed-replace;boundary = --myboundary"); assertEquals("--myboundary", mimeType.getParameter("boundary")); }
@Test // SPR-8917 public void parseMimeTypeQuotedParameterValue() { MimeType mimeType = MimeTypeUtils.parseMimeType("audio/*;attr=\"v>alue\""); assertEquals("\"v>alue\"", mimeType.getParameter("attr")); }
@Test // SPR-8917 public void parseMimeTypeSingleQuotedParameterValue() { MimeType mimeType = MimeTypeUtils.parseMimeType("audio/*;attr='v>alue'"); assertEquals("'v>alue'", mimeType.getParameter("attr")); }
@Test // SPR-16630 public void parseMimeTypeWithSpacesAroundEqualsAndQuotedValue() { MimeType mimeType = MimeTypeUtils.parseMimeType("text/plain; foo = \" bar \" "); assertEquals("\" bar \"", mimeType.getParameter("foo")); }
@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")); }
static String classNameFromMimeType(MimeType mimeType) { Assert.notNull(mimeType, "mimeType cannot be null."); String className = mimeType.getParameter("type"); if (className == null) { return null; } //unwrap quotes if any className = className.replace("\"", ""); // restore trailing ';' if (className.contains("[L")) { className += ";"; } return className; } }
/** * Return the character set, as indicated by a {@code charset} parameter, if any. * @return the character set, or {@code null} if not available * @since 4.3 */ @Nullable public Charset getCharset() { String charset = getParameter(PARAM_CHARSET); return (charset != null ? Charset.forName(unquote(charset)) : null); }
/** * Return the character set, as indicated by a {@code charset} parameter, if any. * @return the character set, or {@code null} if not available * @since 4.3 */ @Nullable public Charset getCharset() { String charset = getParameter(PARAM_CHARSET); return (charset != null ? Charset.forName(unquote(charset)) : null); }
/** * Get the java Object type for the MimeType X_JAVA_OBJECT * * @return the class for the content type */ public static Class<?> getJavaTypeForJavaObjectContentType(MimeType contentType) { Assert.isTrue(X_JAVA_OBJECT.includes(contentType), "Content type must be " + X_JAVA_OBJECT.toString() + ", or " + "included in it"); if (contentType.getParameter("type") != null) { try { return ClassUtils.forName(contentType.getParameter("type"), null); } catch (Exception e) { throw new ConversionException(e.getMessage(), e); } } return Object.class; }
? converterFactory.getMessageConverterForType(contentType) : converterFactory.getMessageConverterForAllRegistered(); String targetClassName = contentType.getParameter("type"); if (StringUtils.hasText(targetClassName)) { try {
? converterFactory.getMessageConverterForType(contentType) : converterFactory.getMessageConverterForAllRegistered(); String targetClassName = contentType.getParameter("type"); if (StringUtils.hasText(targetClassName)) { try {