code: public static String addCharset(String charset, String contentType)
      {
          if (null == contentType)
          {
              return "text/plain;charset=" + charset;
          }
          else
          {
              Matcher matcher = CHARSET_PATT.matcher(contentType);
              if (matcher.find())
              {
                  // replace what ever content-type with the charset
                  return contentType.substring(0, matcher.start(1)) +
                      charset + contentType.substring(matcher.end(1));
              }
              else
              {
                  return contentType + ";charset=" + charset;
              }
          }
      }
docs: Adds the charset to a content type.
  
  @param contentType
  @return the {@code contentType} with {@code charset.name()} appended.