當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaType.getType方法代碼示例

本文整理匯總了Java中org.springframework.http.MediaType.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaType.getType方法的具體用法?Java MediaType.getType怎麽用?Java MediaType.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.MediaType的用法示例。


在下文中一共展示了MediaType.getType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: getHeaders

import org.springframework.http.MediaType; //導入方法依賴的package包/類
@Override
public HttpHeaders getHeaders() {
	if (this.headers == null) {
		this.headers = new HttpHeaders();
		for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements();) {
			String headerName = (String) headerNames.nextElement();
			for (Enumeration<?> headerValues = this.servletRequest.getHeaders(headerName);
					headerValues.hasMoreElements();) {
				String headerValue = (String) headerValues.nextElement();
				this.headers.add(headerName, headerValue);
			}
		}
		// HttpServletRequest exposes some headers as properties: we should include those if not already present
		if (this.headers.getContentType() == null && this.servletRequest.getContentType() != null) {
			MediaType contentType = MediaType.parseMediaType(this.servletRequest.getContentType());
			this.headers.setContentType(contentType);
		}
		if (this.headers.getContentType() != null && this.headers.getContentType().getCharSet() == null &&
				this.servletRequest.getCharacterEncoding() != null) {
			MediaType oldContentType = this.headers.getContentType();
			Charset charSet = Charset.forName(this.servletRequest.getCharacterEncoding());
			Map<String, String> params = new HashMap<String, String>(oldContentType.getParameters());
			params.put("charset", charSet.toString());
			MediaType newContentType = new MediaType(oldContentType.getType(), oldContentType.getSubtype(), params);
			this.headers.setContentType(newContentType);
		}
		if (this.headers.getContentLength() == -1 && this.servletRequest.getContentLength() != -1) {
			this.headers.setContentLength(this.servletRequest.getContentLength());
		}
	}
	return this.headers;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:33,代碼來源:ServletServerHttpRequest.java


注:本文中的org.springframework.http.MediaType.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。