本文整理汇总了Java中com.google.common.net.MediaType.type方法的典型用法代码示例。如果您正苦于以下问题:Java MediaType.type方法的具体用法?Java MediaType.type怎么用?Java MediaType.type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.net.MediaType
的用法示例。
在下文中一共展示了MediaType.type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setContentType
import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Override
public void setContentType(String type) {
if (isCommitted()) {
return;
}
if (hasWriter()) {
return;
}
if (null == type) {
contentType = null;
return;
}
MediaType mediaType = MediaType.parse(type);
Optional<Charset> charset = mediaType.charset();
if (charset.isPresent()) {
setCharacterEncoding(charset.get().name());
}
contentType = mediaType.type() + '/' + mediaType.subtype();
}
示例2: MediaTypeClassifierImpl
import com.google.common.net.MediaType; //导入方法依赖的package包/类
MediaTypeClassifierImpl(Iterable<? extends MediaType> mts) {
Table<String, String, Set<MediaType>> typeTable =
HashBasedTable.<String, String, Set<MediaType>>create();
for (MediaType mt : mts) {
String type = mt.type();
String subtype = mt.subtype();
Set<MediaType> typeSet = typeTable.get(type, subtype);
if (typeSet == null) {
typeSet = Sets.newLinkedHashSet();
typeTable.put(type, subtype, typeSet);
}
typeSet.add(mt);
}
ImmutableTable.Builder<String, String, ImmutableSet<MediaType>> b =
ImmutableTable.builder();
for (Table.Cell<String, String, Set<MediaType>> cell
: typeTable.cellSet()) {
b.put(cell.getRowKey(), cell.getColumnKey(), ImmutableSet.copyOf(cell.getValue()));
}
this.types = b.build();
}
示例3: apply
import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Override
public Classification apply(
UrlValue x, Diagnostic.Receiver<? super UrlValue> r) {
MediaType t = x.getContentMediaType();
if (t == null) {
r.note(Diagnostics.MISSING_MEDIA_TYPE, x);
return Classification.INVALID;
}
String type = t.type();
String subtype = t.subtype();
if ("*".equals(type) || "*".equals(subtype)) {
r.note(Diagnostics.WILDCARD, x);
return Classification.INVALID;
}
if (anyRangeMatches(t, types.get(type, subtype))
|| anyRangeMatches(t, types.get(type, "*"))
|| anyRangeMatches(t, types.get("*", "*"))) {
return Classification.MATCH;
}
r.note(Diagnostics.WITHIN_NO_RANGES, x);
return Classification.NOT_A_MATCH;
}
示例4: setContentType
import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Override
public void setContentType(String type) {
if (isCommitted()) {
return;
}
// if (hasWriter()) {
// return;
// }
if (null == type) {
contentType = null;
return;
}
MediaType mediaType = MediaType.parse(type);
Optional<Charset> charset = mediaType.charset();
if (charset.isPresent()) {
setCharacterEncoding(charset.get().name());
}
contentType = mediaType.type() + '/' + mediaType.subtype();
}