Example usage for org.springframework.http MediaType getCharset

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

Introduction

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

Prototype

@Nullable
public Charset getCharset() 

Source Link

Document

Return the character set, as indicated by a charset parameter, if any.

Usage

From source file:cn.cuizuoli.appranking.http.converter.JsoupHttpMessageConverter.java

private Charset getContentTypeCharset(MediaType contentType) {
    if (contentType != null && contentType.getCharSet() != null) {
        return contentType.getCharSet();
    } else {//from www.  j av  a 2 s  .c  o m
        return this.defaultCharset;
    }
}

From source file:org.craftercms.search.utils.StringHttpMessageConverterExtended.java

private Charset getContentTypeCharset(MediaType contentType) {
    if (contentType != null && contentType.getCharSet() != null) {
        return contentType.getCharSet();
    } else {//from  ww  w  . ja  va2  s. c o m
        return DEFAULT_CHARSET;
    }
}

From source file:com.nextbook.config.ConfigurableStringHttpMessageConverter.java

private Charset getContentTypeCharset(MediaType contentType) {
    if (contentType != null && contentType.getCharSet() != null) {
        return contentType.getCharSet();
    } else {//from   w ww .j a v  a  2 s .c om
        return defaultCharset;
    }
}

From source file:org.cloudfoundry.client.lib.util.StringHttpMessageConverterWithoutMediaType.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    if (writeAcceptCharset) {
        outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    }/*w ww .  j a  v a 2s  .  com*/
    MediaType contentType = outputMessage.getHeaders().getContentType();
    Charset charset = contentType != null && contentType.getCharSet() != null ? contentType.getCharSet()
            : DEFAULT_CHARSET;
    FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}

From source file:sys.core.jackson.MappingJacksonHttpMessageConverter.java

protected JsonEncoding getJsonEncoding(MediaType contentType) {
    if (contentType != null && contentType.getCharSet() != null) {
        Charset charset = contentType.getCharSet();
        for (JsonEncoding encoding : JsonEncoding.values()) {
            if (charset.name().equals(encoding.getJavaName())) {
                return encoding;
            }//w  ww  . j  av a2s. com
        }
    }
    return JsonEncoding.UTF8;
}

From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java

@Override
protected Long getContentLength(String s, MediaType contentType) {
    if (contentType != null && contentType.getCharSet() != null) {
        Charset charset = contentType.getCharSet();
        try {/*from www.  j  a v  a 2  s. c o m*/
            return (long) s.getBytes(charset.name()).length;
        } catch (UnsupportedEncodingException ex) {
            // should not occur
            throw new InternalError(ex.getMessage());
        }
    } else {
        return null;
    }
}

From source file:com.alibaba.webmvc.extension.FastJsonHttpMessageConverter.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    MediaType mediaType = outputMessage.getHeaders().getContentType();
    Charset charset = mediaType.getCharSet();
    if (charset == null) {
        charset = DEFAULT_CHARSET;//  w ww . j  av  a 2 s .c  om
    }
    JSONs.writeTo(outputMessage.getBody(), object, charset, prettyPrint);
}

From source file:com.baomidou.framework.controller.JsonpResponseAdvice.java

@Override
protected MediaType getContentType(MediaType contentType, ServerHttpRequest request,
        ServerHttpResponse response) {/*from   w  w w . j  a  va 2 s  . c om*/
    return new MediaType("application", "javascript", contentType.getCharSet());
}

From source file:model.ConfigurableStringHttpMessageConverter.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    MediaType contentType = outputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
    FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}

From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java

@Override
protected String readInternal(@SuppressWarnings("rawtypes") Class clazz, HttpInputMessage inputMessage)
        throws IOException {
    MediaType contentType = inputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
    return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
}