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


Java ContentType.get方法代碼示例

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


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

示例1: ensureJsonContent

import org.apache.http.entity.ContentType; //導入方法依賴的package包/類
private static ContentType ensureJsonContent(HttpEntity entity)
        throws ClientProtocolException {
    ContentType type = ContentType.get(entity);
    String expected = ContentType.APPLICATION_JSON     // (1)
                                 .toString()
                                 .replace(" ", "");    // (2)
    if (type == null) {
        throw new ClientProtocolException("Unspecified content type.");
    }
    String actual = type.toString().replace(" ", "");  // (2)
    if (!expected.equalsIgnoreCase(actual)) {
        throw new ClientProtocolException(
                String.format("Invalid content type: %s", actual));
    }
    return type;
}
 
開發者ID:openmicroscopy,項目名稱:omero-ms-queue,代碼行數:17,代碼來源:JsonEntity.java

示例2: parse

import org.apache.http.entity.ContentType; //導入方法依賴的package包/類
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an
 * {@link HttpEntity}. The encoding is taken from the entity's
 * Content-Encoding header.
 * <p>
 * This is typically used while parsing an HTTP POST.
 *
 * @param entity
 *            The entity to parse
 * @throws IOException
 *             If there was an exception getting the entity's data.
 */
public static List <NameValuePair> parse (
        final HttpEntity entity) throws IOException {
    ContentType contentType = ContentType.get(entity);
    if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) {
        String content = EntityUtils.toString(entity, Consts.ASCII);
        if (content != null && content.length() > 0) {
            Charset charset = contentType.getCharset();
            if (charset == null) {
                charset = HTTP.DEF_CONTENT_CHARSET;
            }
            return parse(content, charset);
        }
    }
    return Collections.emptyList();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:URLEncodedUtils.java

示例3: handleResponse

import org.apache.http.entity.ContentType; //導入方法依賴的package包/類
@Override
public AuthenticationResponse handleResponse(final HttpResponse response) throws IOException {
    if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        Charset charset = HTTP.DEF_CONTENT_CHARSET;
        ContentType contentType = ContentType.get(response.getEntity());
        if(contentType != null) {
            if(contentType.getCharset() != null) {
                charset = contentType.getCharset();
            }
        }
        try {
            final JsonParser parser = new JsonParser();
            final JsonObject json = parser.parse(new InputStreamReader(response.getEntity().getContent(), charset)).getAsJsonObject();
            final String token = json.getAsJsonPrimitive("token").getAsString();
            final String endpoint = json.getAsJsonPrimitive("endpoint").getAsString();
            return new AuthenticationResponse(response, token,
                    Collections.singleton(new Region(null, URI.create(endpoint), null, true)));
        }
        catch(JsonParseException e) {
            throw new IOException(e.getMessage(), e);
        }
    }
    else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
            || response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) {
        throw new AuthorizationException(new Response(response));
    }
    throw new GenericException(new Response(response));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:29,代碼來源:HubicAuthenticationResponseHandler.java

示例4: setResponse

import org.apache.http.entity.ContentType; //導入方法依賴的package包/類
public void setResponse(CloseableHttpResponse response) throws UnsupportedOperationException, IOException {
	this.response = response;
	if(response.getEntity()!=null) {
		byte[] byteArray = IOUtils.toByteArray(response.getEntity().getContent());
		ContentType contentType = ContentType.get(response.getEntity());
		response.close();
		this.content=new Content(byteArray, contentType);
	}
}
 
開發者ID:nfreire,項目名稱:LDN4IIIF,代碼行數:10,代碼來源:FetchRequest.java

示例5: getCharset

import org.apache.http.entity.ContentType; //導入方法依賴的package包/類
/**
 * 獲取響應編碼,如果是文本的話
 * 
 * 
 * @date 2015年7月18日
 * @return
 */
public Charset getCharset() {
	ContentType contentType = ContentType.get(entity);
	if (contentType == null)
		return null;
	return contentType.getCharset();
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:14,代碼來源:ResponseWrap.java


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