code: public static String getCharsetFromContentType(Header header) {
          if (header == null || header.getValue()==null || "".equals(header.getValue())) return null;
          Matcher m = charsetPattern.matcher(header.getValue());
          if (m.find()) {
              return m.group(1).trim().toUpperCase();
          }
          return null;
      }
docs: Parse out a charset from a content type header.
  @param header e.g. "text/html; charset=EUC-JP"
  @return "EUC-JP", or null if not found. Charset is trimmed and uppercased.