{@inheritDoc}

@throws InvalidContentTypeException if the response is invalid
352044
@Override
    public Capabilities getResponse(final byte[] content, final String mimeType)
            throws ContentException {
        if (mimeType == null || !mimeType.startsWith(TEXT_PLAIN)) {
            LOGGER.warn(
                    "Content-Type mismatch: was '{}', expected 'text/plain'",
                    mimeType);
        }

        final EnumSet<Capability> caps = EnumSet.noneOf(Capability.class);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("CA capabilities:");
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                new ByteArrayInputStream(content),
                Charset.forName(Charsets.US_ASCII.name())));
        Set<String> caCaps = new HashSet<String>();
        String capability;
        try {
            while ((capability = reader.readLine()) != null) {
                caCaps.add(capability);
            }
        } catch (IOException e) {
            throw new InvalidContentTypeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                LOGGER.error("Error closing reader", e);
            }
        }

        for (Capability enumValue : Capability.values()) {
            if (caCaps.contains(enumValue.toString())) {
                LOGGER.debug("[\u2713] {}", enumValue.getDescription());
                caps.add(enumValue);
            } else {
                LOGGER.debug("[\u2717] {}", enumValue.getDescription());
            }
        }

        return new Capabilities(caps.toArray(new Capability[caps.size()]));
    }
11683
public function setContentHeader($contentType, $charset = 'UTF-8')
    {
        if (!$this->response) {
           return $this->getResponse()->setContentHeader($contentType, $charset);
        }
        return parent::setContentHeader($contentType, $charset);
    }
929948
public function setContentType($contentType)
    {
        $allowedValues = $this->getContentTypeAllowableValues();
        if (!is_null($contentType) && !in_array($contentType, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'contentType', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['contentType'] = $contentType;

        return $this;
    }
236477
@Override
    public void setContentType(String value) {
        if (isCommitted()) {
            return;
        }
        if (null == value) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "setContentType: null, removing header");
            }
            this.response.removeHeader("Content-Type");
            return;
        }
        boolean addEncoding = false;
        String type = value;

        // see if the input value contains a charset
        int charsetIndex = value.indexOf("charset=");
        if (-1 != charsetIndex) {
            if (null == this.outWriter) {
                // can update both mime-set and charset
                addEncoding = true;
                this.encoding = connection.getEncodingUtils().stripQuotes(value.substring(charsetIndex + 8));
            } else {
                // can only update the mimeset so strip the charset off
                type = value.substring(0, charsetIndex).trim();
                charsetIndex = -1;
            }
        }
        if (null != this.outWriter) {
            // can still update the mime-type but not charset
            addEncoding = true;
        } else {
            // TODO don't quite follow why webcontainer checks for text*
            if (type.startsWith("text")) {
                addEncoding = true;
            }
        }
        if (addEncoding) {
            if (-1 != charsetIndex) {
                type = type.substring(0, charsetIndex - 1);
            }
            if (this.encoding != null) {
                type = type + ";charset=" + this.encoding;
            }
        }
        this.contentType = type;
        this.response.setHeader("Content-Type", type);
    }
235002
public function getContentType()
    {
        switch ($this->input->getFormat()) {

            case InputInterface::FORMAT_JSON:
                return ClientInterface::CONTENT_TYPE_JSON;
                break;

            case InputInterface::FORMAT_TEXT:
                return ClientInterface::CONTENT_TYPE_TEXT;
                break;

            default:
                throw new \LogicException('Allowed invalid input format to be set.');
        }
    }
951914
private void invalidByte(int position, int count, int c) 
        throws UTFDataFormatException {

        String msg = JspCoreException.getMsg("jsp.error.xml.invalidByte", new Object[] {Integer.toString(position), Integer.toString(count)});
        throw new UTFDataFormatException(msg);
    }
1311583
public function isSatisfiedBy($contentType): bool
    {
        if (!$contentType instanceof ContentType) {
            throw new InvalidArgumentException($contentType, sprintf('Must be instance of %s', ContentType::class));
        }

        return in_array($contentType->identifier, $this->userGroupContentTypeIdentifier, true);
    }
1197974
def on_valid(valid_content_type, on_invalid=json):
    """"""
    invalid_kwargs = introspect.generate_accepted_kwargs(on_invalid, 'request', 'response')
    invalid_takes_response = introspect.takes_all_arguments(on_invalid, 'response')

    def wrapper(function):
        valid_kwargs = introspect.generate_accepted_kwargs(function, 'request', 'response')
        valid_takes_response = introspect.takes_all_arguments(function, 'response')

        @content_type(valid_content_type)
        @wraps(function)
        def output_content(content, response, **kwargs):
            if type(content) == dict and 'errors' in content:
                response.content_type = on_invalid.content_type
                if invalid_takes_response:
                    kwargs['response'] = response
                return on_invalid(content, **invalid_kwargs(kwargs))

            if valid_takes_response:
                kwargs['response'] = response
            return function(content, **valid_kwargs(kwargs))
        return output_content
    return wrapper
291851
private void setContentTypeHeader(final HttpResponse response, final URLConnection connection) {
    response.headers().set(CONTENT_TYPE, mimeTypesMap.getContentType(connection.getURL().getPath()));
  }
1036892
function isAndroidCustomContentValid(customContent){

	var isValid = true;

	if(typeof customContent !== 'object'){
		isValid = false;
	}else{
		for(var key in customContent){
			if(typeof customContent[key] !== 'string'){
				isValid = false;
				break;
			}
		}
	}

	return isValid;
}
1357522
private function checkIfRequestIsValidOrThrowException($invalidValues)
    {
        if (!empty($invalidValues)) {
            $exception = new InvalidRequestException('Errors occurred while parsing the request');
            $exception->setErrors($invalidValues);
            throw $exception;
        }
    }
521932
private function preVerifyContentType(RequestInterface $request, $retryWithUrlEncodingDisabled = null)
    {
        $configuration = $this->getConfiguration();

        try {
            $response = $configuration->getHttpClient()->send($request);
        } catch (BadResponseException $badResponseException) {
            if (is_null($retryWithUrlEncodingDisabled) && $configuration->getRetryWithUrlEncodingDisabled()) {
                $retryWithUrlEncodingDisabled = true;
            }

            if ($retryWithUrlEncodingDisabled) {
                return $this->preVerifyContentType($this->deEncodeRequestUrl($request), false);
            }

            $response = $badResponseException->getResponse();
        }

        if (!$this->isSuccessResponse($response)) {
            return null;
        }

        $contentType = $this->getContentTypeFromResponse($response);

        $hasMappedWebResourceClassName = $configuration->hasMappedWebResourceClassName(
            $contentType->getTypeSubtypeString()
        );

        if (!$hasMappedWebResourceClassName && !$configuration->getAllowUnknownResourceTypes()) {
            throw new InvalidContentTypeException($contentType, $response, $request);
        }

        return true;
    }
123590
public static function create(string $content): InvalidContentException
    {
        $template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
        $message = sprintf($template, $content);

        return new static($message);
    }
1358723
protected function validateResponseContent($response)
    {
        if (isset($response['error_description'])) {
            throw new AuthenticationException(sprintf('OAuth error: "%s"', $response['error_description']));
        }

        if (isset($response['error'])) {
            throw new AuthenticationException(sprintf('OAuth error: "%s"', $response['error']['message'] ?? $response['error']));
        }

        if (!isset($response['access_token'])) {
            throw new AuthenticationException('Not a valid access token.');
        }
    }
513087
function validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute )
    {
        $maxLen = $classAttribute->attribute( self::MAX_LEN_FIELD );
        $textCodec = eZTextCodec::instance( false );
        if ( $textCodec->strlen( $data ) > $maxLen and
             $maxLen > 0 )
        {
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                 'The input text is too long. The maximum number of characters allowed is %1.' ),
                                                         $maxLen );
            return eZInputValidator::STATE_INVALID;
        }
        return eZInputValidator::STATE_ACCEPTED;
    }
1037061
public function setContent($content = null)
    {
        if (null !== $content && !is_string($content)) {
            throw new ResponseException('Response content must be a string.');
        }

        $this->content = (string) $content;

        return $this;
    }
626054
private function checkContent($content)
    {
        if (! is_array($content) and ! is_string($content)) {
            throw new InvalidTypeException(
                'The content must be an array or string value, ' . gettype($content) . ' is given.'
            );
        }

        $this->checkSingleValuedContent($content);

        return is_array($content) ? $content : [$content];
    }