/**
* <em>Replaces</em> all parameters with the given attribute with a single parameter with the
* given value. If multiple parameters with the same attributes are necessary use
* {@link #withParameters}. Prefer {@link #withCharset} for setting the {@code charset} parameter
* when using a {@link Charset} object.
*
* @throws IllegalArgumentException if either {@code attribute} or {@code value} is invalid
*/
public MediaType withParameter(String attribute, String value) {
checkNotNull(attribute);
checkNotNull(value);
String normalizedAttribute = normalizeToken(attribute);
ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
for (Entry<String, String> entry : parameters.entries()) {
String key = entry.getKey();
if (!normalizedAttribute.equals(key)) {
builder.put(key, entry.getValue());
}
}
builder.put(normalizedAttribute, normalizeParameterValue(normalizedAttribute, value));
MediaType mediaType = new MediaType(type, subtype, builder.build());
// Return one of the constants if the media type is a known type.
return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
MediaType.java 文件源码
java
阅读 46
收藏 0
点赞 0
评论 0
项目:googles-monorepo-demo
作者:
评论列表
文章目录