本文整理汇总了Java中org.springframework.http.MediaType.getCharSet方法的典型用法代码示例。如果您正苦于以下问题:Java MediaType.getCharSet方法的具体用法?Java MediaType.getCharSet怎么用?Java MediaType.getCharSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.MediaType
的用法示例。
在下文中一共展示了MediaType.getCharSet方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readInternal
import org.springframework.http.MediaType; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
WireFeedInput feedInput = new WireFeedInput();
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset;
if (contentType != null && contentType.getCharSet() != null) {
charset = contentType.getCharSet();
} else {
charset = DEFAULT_CHARSET;
}
try {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
return (T) feedInput.build(reader);
}
catch (FeedException ex) {
throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex);
}
}
示例2: getContentInfo
import org.springframework.http.MediaType; //导入方法依赖的package包/类
/**
* Returns the basic content info from the request.
* @param req WebScriptRequest
* @return BasicContentInfo
*/
private BasicContentInfo getContentInfo(WebScriptRequest req) {
String encoding = "UTF-8";
String contentType = MimetypeMap.MIMETYPE_BINARY;
if (StringUtils.isNotEmpty(req.getContentType()))
{
MediaType media = MediaType.parseMediaType(req.getContentType());
contentType = media.getType()+'/'+media.getSubtype();
if (media.getCharSet() != null)
{
encoding = media.getCharSet().toString();
}
}
return new ContentInfoImpl(contentType, encoding, -1, Locale.getDefault());
}
示例3: getJsonEncoding
import org.springframework.http.MediaType; //导入方法依赖的package包/类
/**
* Determine the JSON encoding to use for the given content type.
* @param contentType the media type as requested by the caller
* @return the JSON encoding to use (never {@code null})
*/
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;
}
}
}
return JsonEncoding.UTF8;
}
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:17,代码来源:AbstractJackson2HttpMessageConverter.java
示例4: getContentTypeCharset
import org.springframework.http.MediaType; //导入方法依赖的package包/类
private Charset getContentTypeCharset(MediaType contentType) {
if (contentType != null && contentType.getCharSet() != null) {
return contentType.getCharSet();
} else {
return DEFAULT_CHARSET;
}
}
示例5: determineEncoding
import org.springframework.http.MediaType; //导入方法依赖的package包/类
private String determineEncoding(String contentTypeHeader, String defaultEncoding) {
if (!StringUtils.hasText(contentTypeHeader)) {
return defaultEncoding;
}
MediaType contentType = MediaType.parseMediaType(contentTypeHeader);
Charset charset = contentType.getCharSet();
return (charset != null ? charset.name() : defaultEncoding);
}
示例6: writeForm
import org.springframework.http.MediaType; //导入方法依赖的package包/类
private void writeForm(MultiValueMap<String, String> form, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException {
Charset charset;
if (contentType != null) {
outputMessage.getHeaders().setContentType(contentType);
charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
}
else {
outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
charset = this.charset;
}
StringBuilder builder = new StringBuilder();
for (Iterator<String> nameIterator = form.keySet().iterator(); nameIterator.hasNext();) {
String name = nameIterator.next();
for (Iterator<String> valueIterator = form.get(name).iterator(); valueIterator.hasNext();) {
String value = valueIterator.next();
builder.append(URLEncoder.encode(name, charset.name()));
if (value != null) {
builder.append('=');
builder.append(URLEncoder.encode(value, charset.name()));
if (valueIterator.hasNext()) {
builder.append('&');
}
}
}
if (nameIterator.hasNext()) {
builder.append('&');
}
}
byte[] bytes = builder.toString().getBytes(charset.name());
outputMessage.getHeaders().setContentLength(bytes.length);
StreamUtils.copy(bytes, outputMessage.getBody());
}
示例7: getContentTypeCharset
import org.springframework.http.MediaType; //导入方法依赖的package包/类
private Charset getContentTypeCharset(MediaType contentType) {
if (contentType != null && contentType.getCharSet() != null) {
return contentType.getCharSet();
}
else {
return this.defaultCharset;
}
}
示例8: getCharset
import org.springframework.http.MediaType; //导入方法依赖的package包/类
private Charset getCharset(ClientHttpResponse response) {
HttpHeaders headers = response.getHeaders();
MediaType contentType = headers.getContentType();
return contentType != null ? contentType.getCharSet() : null;
}
示例9: setCharset
import org.springframework.http.MediaType; //导入方法依赖的package包/类
private void setCharset(MediaType contentType, Marshaller marshaller) throws PropertyException {
if (contentType != null && contentType.getCharSet() != null) {
marshaller.setProperty(Marshaller.JAXB_ENCODING, contentType.getCharSet().name());
}
}