/** * Creates a content type from an existing content type and an additional parameter as key-value pair. * @param contentType an existing content type * @param parameterName the name of the additional parameter * @param parameterValue the value of the additional parameter * @return a new {@link ContentType} object */ public static ContentType create(final ContentType contentType, final String parameterName, final String parameterValue) throws IllegalArgumentException { TypeUtil.validateParameterNameAndValue(parameterName, parameterValue); ContentType type = new ContentType(contentType.type, contentType.subtype, contentType.parameters); type.parameters.put(parameterName.toLowerCase(Locale.ROOT), parameterValue); return type; }
/** * Creates a content type from an existing content type and an additional parameter as key-value pair. * @param contentType an existing content type * @param parameterName the name of the additional parameter * @param parameterValue the value of the additional parameter * @return a new {@link ContentType} object */ public static ContentType create(final ContentType contentType, final String parameterName, final String parameterValue) throws IllegalArgumentException { TypeUtil.validateParameterNameAndValue(parameterName, parameterValue); ContentType type = new ContentType(contentType.type, contentType.subtype, contentType.parameters); type.parameters.put(parameterName.toLowerCase(Locale.ROOT), parameterValue); return type; }
/** * Creates a {@link ContentType} based on given input string (<code>format</code>). Supported format is * <code>Media Type</code> format as defined in RFC 7231, chapter 3.1.1.1. * * @param format a string in format as defined in RFC 7231, chapter 3.1.1.1 * @return a new {@link ContentType} object * @throws IllegalArgumentException if input string is not parseable */ public static ContentType create(final String format) throws IllegalArgumentException { if (format == null) { throw new IllegalArgumentException("Parameter format MUST NOT be NULL."); } List<String> typeSubtype = new ArrayList<String>(); Map<String, String> parameters = new HashMap<String, String>(); parse(format, typeSubtype, parameters); return new ContentType(typeSubtype.get(0), typeSubtype.get(1), parameters); }
/** * Creates a {@link ContentType} based on given input string (<code>format</code>). Supported format is * <code>Media Type</code> format as defined in RFC 7231, chapter 3.1.1.1. * * @param format a string in format as defined in RFC 7231, chapter 3.1.1.1 * @return a new {@link ContentType} object * @throws IllegalArgumentException if input string is not parseable */ public static ContentType create(final String format) throws IllegalArgumentException { if (format == null) { throw new IllegalArgumentException("Parameter format MUST NOT be NULL."); } List<String> typeSubtype = new ArrayList<String>(); Map<String, String> parameters = new HashMap<String, String>(); parse(format, typeSubtype, parameters); return new ContentType(typeSubtype.get(0), typeSubtype.get(1), parameters); }