Example usage for org.springframework.http MediaType getParameters

List of usage examples for org.springframework.http MediaType getParameters

Introduction

In this page you can find the example usage for org.springframework.http MediaType getParameters.

Prototype

public Map<String, String> getParameters() 

Source Link

Document

Return all generic parameter values.

Usage

From source file:org.springframework.http.codec.EncoderHttpMessageWriter.java

private boolean isStreamingMediaType(@Nullable MediaType contentType) {
    return (contentType != null && this.encoder instanceof HttpMessageEncoder
            && ((HttpMessageEncoder<?>) this.encoder).getStreamingMediaTypes().stream()
                    .anyMatch(streamingMediaType -> contentType.isCompatibleWith(streamingMediaType)
                            && contentType.getParameters().entrySet()
                                    .containsAll(streamingMediaType.getParameters().keySet())));
}

From source file:org.springframework.http.server.reactive.ServletServerHttpRequest.java

private static HttpHeaders initHeaders(HttpServletRequest request) {
    HttpHeaders headers = new HttpHeaders();
    for (Enumeration<?> names = request.getHeaderNames(); names.hasMoreElements();) {
        String name = (String) names.nextElement();
        for (Enumeration<?> values = request.getHeaders(name); values.hasMoreElements();) {
            headers.add(name, (String) values.nextElement());
        }//from  w w w . jav  a  2s .  c  o  m
    }
    MediaType contentType = headers.getContentType();
    if (contentType == null) {
        String requestContentType = request.getContentType();
        if (StringUtils.hasLength(requestContentType)) {
            contentType = MediaType.parseMediaType(requestContentType);
            headers.setContentType(contentType);
        }
    }
    if (contentType != null && contentType.getCharset() == null) {
        String encoding = request.getCharacterEncoding();
        if (StringUtils.hasLength(encoding)) {
            Charset charset = Charset.forName(encoding);
            Map<String, String> params = new LinkedCaseInsensitiveMap<>();
            params.putAll(contentType.getParameters());
            params.put("charset", charset.toString());
            headers.setContentType(new MediaType(contentType.getType(), contentType.getSubtype(), params));
        }
    }
    if (headers.getContentLength() == -1) {
        int contentLength = request.getContentLength();
        if (contentLength != -1) {
            headers.setContentLength(contentLength);
        }
    }
    return headers;
}