if (type == null) {
return null;
}
int semi = type.indexOf(";");
if (semi == -1) {
return null;
}
int charsetLocation = type.indexOf("charset=", semi);
if (charsetLocation == -1) {
return null;
}
String afterCharset = type.substring(charsetLocation + 8);
// The charset value in a Content-Type header is allowed to be quoted
// and charset values can't contain quotes. Just convert any quote
// chars into spaces and let trim clean things up.
afterCharset = afterCharset.replace('"", ' ");
String encoding = afterCharset.trim();
return encoding;