当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.getCharSet方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AbstractWireFeedHttpMessageConverter.java

示例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());
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:23,代码来源:ResourceWebScriptPut.java

示例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;
	}
}
 
开发者ID:yi-jun,项目名称:aaden-pay,代码行数:8,代码来源:SpringHttpMessageConverter.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:CommonsFileUploadSupport.java

示例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());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:FormHttpMessageConverter.java

示例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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:StringHttpMessageConverter.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:6,代码来源:DefaultResponseErrorHandler.java

示例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());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:6,代码来源:Jaxb2RootElementHttpMessageConverter.java


注:本文中的org.springframework.http.MediaType.getCharSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。