Parse the character encoding from the specified content type header. If
the content type is null, or there is no explicit character encoding,
<code>null</code> is returned.

@param contentType
a content type header
8096
public static String parseCharacterEncoding( final String contentType )
    {

        if ( contentType == null )
        {
            return ( null );
        }
        final int start = contentType.indexOf( "charset=" );
        if ( start < 0 )
        {
            return ( null );
        }
        String encoding = contentType.substring( start + 8 );
        final int end = encoding.indexOf( ';' );
        if ( end >= 0 )
        {
            encoding = encoding.substring( 0, end );
        }
        encoding = encoding.trim();
        if ( ( encoding.length() > 2 ) && ( encoding.startsWith( "\"" ) ) && ( encoding.endsWith( "\"" ) ) )
        {
            encoding = encoding.substring( 1, encoding.length() - 1 );
        }
        return ( encoding.trim() );

    }
1119622
public static String getContentTypeByRequestBody(String body) {
		final ContentType contentType = ContentType.get(body);
		return (null == contentType) ? null : contentType.toString();
	}
137158
def _parse_content_type(content_type: Optional[str]) -> Tuple[Optional[str], str]:
    
    if not content_type:
        return None, "utf-8"
    else:
        type_, parameters = cgi.parse_header(content_type)
        encoding = parameters.get("charset", "utf-8")
        return type_, encoding
1070213
public function setContentType($contentType) {
    $this->contentType = $contentType;
    
    $ct = $this->contentType;
    if (isset($this->charset))
      $ct .= '; charset='.$this->charset;

    $this->setMeta('content-type',$ct, TRUE);
  }
52797
public Response contentType(String contentType) {
        checkCommitted();

        header(HttpConstants.Header.CONTENT_TYPE, contentType);
        httpServletResponse.setContentType(contentType);

        return this;
    }
1179029
private void checkContentType(String contentType) {
		if(contentType == null) {
			throw new IllegalArgumentException("the content type cannot be null");
		}
		int indexOfSlash = contentType.indexOf("/");
		if(indexOfSlash != -1) {
			if(!JainSipUtils.IANA_ALLOWED_CONTENT_TYPES.contains(contentType.substring(0, indexOfSlash))) {
				throw new IllegalArgumentException("the given content type " + contentType + " is not allowed");
			}
		} else if(!JainSipUtils.IANA_ALLOWED_CONTENT_TYPES.contains(contentType.toLowerCase())) {
			throw new IllegalArgumentException("the given content type " + contentType + " is not allowed");
		}
	}
230848
public boolean matchContentType(String contentTypeRegex) {
        if (contentTypeRegex == null) {
            return contentType() == null;
        }
        return Pattern.matches(contentTypeRegex, contentType());
    }
238414
public static Charset getCharset(CharSequence contentTypeValue) {
        if (contentTypeValue != null) {
            return getCharset(contentTypeValue, CharsetUtil.ISO_8859_1);
        } else {
            return CharsetUtil.ISO_8859_1;
        }
    }
661714
public KieServerHttpRequest contentType(final String contentType, final String charset ) {
        if( charset != null && charset.length() > 0 ) {
            final String separator = "; " + PARAM_CHARSET + '=';
            return header(CONTENT_TYPE, contentType + separator + charset);
        } else
            return header(CONTENT_TYPE, contentType);
    }
767841
public void setContentType(String contentType) throws InvalidArgumentException {
    if (Strings.isNullOrEmpty(contentType)) {
      throw new InvalidArgumentException("empty content type");
    }

    this.contentType = contentType;
  }
461914
@Trivial
    @Override
    public String getCharacterEncoding() {
        if (null != this.encoding) {
            return this.encoding;
        }

        EncodingUtils encodingUtils = connection.getEncodingUtils();

        String enc = null;
        // parse content-type to see if it's set there
        String type = this.request.getHeader("Content-Type");
        if (null != type) {
            enc = encodingUtils.getCharsetFromContentType(type);
            if (!encodingUtils.isCharsetSupported(enc)) {
                enc = null;
            }
        }

        // now get the appropriate match (may be set in the properties)
        this.encoding = encodingUtils.getJvmConverter(enc);

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getCharacterEncoding: set to " + this.encoding);
        }
        return this.encoding;
    }
999206
public static String getCharsetFromContentType(String type) {
    	init();
        if (type == null) {
            return null;
        }

        int semi = type.indexOf(";");

        if (semi == -1) {
            return null;
        }

        String afterSemi = type.substring(semi + 1);

        int charsetLocation = afterSemi.indexOf("charset=");

        if (charsetLocation == -1) {
            return null;
        }

        return afterSemi.substring(charsetLocation + 8).trim();
    }
946697
public List<ContentCodingType> getContentEncoding() {
		String value = getFirst(CONTENT_ENCODING);
		return (value != null ? ContentCodingType.parseCodingTypes(value) : Collections.<ContentCodingType>emptyList());
	}
1091758
protected Charset guessContentTypeCharset(final HttpURLConnection connection) {
		String contentType = connection.getHeaderField(CONTENT_TYPE_HEADER);
		if (contentType == null) {
			return UTF8;
		}

		String charset = null;
		for (String param : contentType.replace(" ", "").split(";")) {
			if (param.startsWith("charset=")) {
				charset = param.split("=", 2)[1];
				break;
			}
		}

		try {
			return Charset.forName(charset);
		} catch (Exception e) {
			return UTF8;
		}
	}
636377
public function setContentType($contentType, $charset=NULL){
        $this->setHeader("Content-Type", $contentType);
        if($charset != NULL){
            $this->setHeader("charset", $charset);
        }
    }
990345
public function setContentType($content_type, $charset = null)
    {
        $this->params['content-type'] = $content_type;
        if ($charset !== null) {
            $this->setCharset($charset);
        }

        return $this;
    }
1268218
protected Set<String> getContentTypes(String contentType) {
        if (StringUtils.isNullOrEmpty(contentType)) {
            return Collections.emptySet();
        }

        Set<String> set = new LinkedHashSet<>();
        String[] types = contentType.split(",");
        for (String type : types) {
            if (type.contains(";")) {
                // drop ;q=0.8 quality scores
                type = type.substring(0, type.indexOf(';'));
            }

            set.add(type.trim().toLowerCase());
        }

        return set;
    }