当前位置: 首页>>代码示例>>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;未经允许,请勿转载。