當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。