code: public static MediaType parse(String string) {
          if(string==null) return null;
  
          Map<String, String> params =  new HashMap<>();
          Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
          if (!typeSubtype.lookingAt()) return null;
          String type = typeSubtype.group(1).toLowerCase(Locale.US);
          String subtype = typeSubtype.group(2).toLowerCase(Locale.US);
  
          String charset = null;
          Matcher parameter = PARAMETER.matcher(string);
          for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
              parameter.region(s, string.length());
              if (!parameter.lookingAt()) return null; // This is not a well-formed media type.
  
              String name = parameter.group(1);
              if (name == null) continue;
              String param = parameter.group(2) != null
                      ? parameter.group(2)  // Value is a token.
                      : parameter.group(3); // Value is a quoted string.
              if(name.equalsIgnoreCase("charset")) {
                  if (charset != null && !param.equalsIgnoreCase(charset)) {
                      throw new IllegalArgumentException("Multiple different charsets: " + string);
                  }
                  charset = param;
              } else {
                  params.put(name, param);
              }
          }
          return new MediaType(string, type, subtype, charset, Collections.unmodifiableMap(params));
      }
docs: Returns a media type for {@code string}, or null if {@code string} is not a
  well-formed media type.