示例#1
0
 public static MediaType valueOf(String value) {
   if (StringUtils.isEmpty(value)) {
     return WILDCARD_TYPE;
   }
   int s = value.indexOf('/');
   if (s < 1) {
     return WILDCARD_TYPE;
   }
   String type = value.substring(0, s);
   int p = value.indexOf(';');
   String subType = "*";
   Map<String, String> parameterMap = null;
   if (p > s) {
     subType = value.substring(s + 1, p);
     parameterMap = Maps.newEmptyHashMap();
     for (String param : StringUtils.split(value.substring(p + 1), ';')) {
       List<String> sp = StringUtils.split(param.trim(), '=');
       if (sp.size() > 1) {
         parameterMap.put(sp.get(0), sp.get(1));
       }
     }
   } else {
     subType = value.substring(s + 1);
   }
   return new DefaultMediaType(type, subType, parameterMap);
 }
示例#2
0
 @SuppressWarnings("unchecked")
 DefaultMediaType(String type, String subType, Map<String, String> parameters) {
   this.type = (StringUtils.isEmpty(type)) ? WILDCARD_VALUE : type;
   this.subType = (StringUtils.isEmpty(subType)) ? WILDCARD_VALUE : subType;
   this.parameters =
       (Map<String, String>)
           ((parameters == null) ? Maps.newEmptyHashMap() : initParameters(parameters));
   this.parameters = Collections.unmodifiableMap(this.parameters);
 }