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


Java HttpEntity.getContentType方法代码示例

本文整理汇总了Java中ch.boye.httpclientandroidlib.HttpEntity.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java HttpEntity.getContentType方法的具体用法?Java HttpEntity.getContentType怎么用?Java HttpEntity.getContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.boye.httpclientandroidlib.HttpEntity的用法示例。


在下文中一共展示了HttpEntity.getContentType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContentCharSet

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
 * Obtains character set of the entity, if known.
 *
 * @param entity must not be null
 * @return the character set, or null if not found
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null
 *
 * @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)}
 */
@Deprecated
public static String getContentCharSet(final HttpEntity entity) throws ParseException {
    Args.notNull(entity, "Entity");
    String charset = null;
    if (entity.getContentType() != null) {
        final HeaderElement values[] = entity.getContentType().getElements();
        if (values.length > 0) {
            final NameValuePair param = values[0].getParameterByName("charset");
            if (param != null) {
                charset = param.getValue();
            }
        }
    }
    return charset;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:26,代码来源:EntityUtils.java

示例2: get

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
 * Extracts <code>Content-Type</code> value from {@link HttpEntity} exactly as
 * specified by the <code>Content-Type</code> header of the entity. Returns <code>null</code>
 * if not specified.
 *
 * @param entity HTTP entity
 * @return content type
 * @throws ParseException if the given text does not represent a valid
 * <code>Content-Type</code> value.
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 * this instance of the Java virtual machine
 */
public static ContentType get(
        final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
    if (entity == null) {
        return null;
    }
    final Header header = entity.getContentType();
    if (header != null) {
        final HeaderElement[] elements = header.getElements();
        if (elements.length > 0) {
            return create(elements[0]);
        }
    }
    return null;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:27,代码来源:ContentType.java

示例3: isEncoded

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
 * Returns true if the entity's Content-Type header is
 * <code>application/x-www-form-urlencoded</code>.
 */
public static boolean isEncoded(final HttpEntity entity) {
    final Header h = entity.getContentType();
    if (h != null) {
        final HeaderElement[] elems = h.getElements();
        if (elems.length > 0) {
            final String contentType = elems[0].getName();
            return contentType.equalsIgnoreCase(CONTENT_TYPE);
        }
    }
    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:URLEncodedUtils.java

示例4: getContentMimeType

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
 * Obtains MIME type of the entity, if known.
 *
 * @param entity must not be null
 * @return the character set, or null if not found
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null
 *
 * @since 4.1
 *
 * @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)}
 */
@Deprecated
public static String getContentMimeType(final HttpEntity entity) throws ParseException {
    Args.notNull(entity, "Entity");
    String mimeType = null;
    if (entity.getContentType() != null) {
        final HeaderElement values[] = entity.getContentType().getElements();
        if (values.length > 0) {
            mimeType = values[0].getName();
        }
    }
    return mimeType;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:25,代码来源:EntityUtils.java

示例5: getContentType

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
 * Fetch the content type of the HTTP response body.
 *
 * @return a <code>Header</code> instance, or <code>null</code> if there was
 *         no body or no valid Content-Type.
 */
public Header getContentType() {
  HttpEntity entity = this.response.getEntity();
  if (entity == null) {
    return null;
  }
  return entity.getContentType();
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:14,代码来源:MozResponse.java

示例6: process

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    if (request instanceof HttpEntityEnclosingRequest) {
        if (this.overwrite) {
            request.removeHeaders(HTTP.TRANSFER_ENCODING);
            request.removeHeaders(HTTP.CONTENT_LEN);
        } else {
            if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
                throw new ProtocolException("Transfer-encoding header already present");
            }
            if (request.containsHeader(HTTP.CONTENT_LEN)) {
                throw new ProtocolException("Content-Length header already present");
            }
        }
        final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        final HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
        if (entity == null) {
            request.addHeader(HTTP.CONTENT_LEN, "0");
            return;
        }
        // Must specify a transfer encoding or a content length
        if (entity.isChunked() || entity.getContentLength() < 0) {
            if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
                throw new ProtocolException(
                        "Chunked transfer encoding not allowed for " + ver);
            }
            request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else {
            request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }
        // Specify a content type if known
        if (entity.getContentType() != null && !request.containsHeader(
                HTTP.CONTENT_TYPE )) {
            request.addHeader(entity.getContentType());
        }
        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !request.containsHeader(
                HTTP.CONTENT_ENCODING)) {
            request.addHeader(entity.getContentEncoding());
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:44,代码来源:RequestContent.java

示例7: process

import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
 * Processes the response (possibly updating or inserting) Content-Length and Transfer-Encoding headers.
 * @param response The HttpResponse to modify.
 * @param context Unused.
 * @throws ProtocolException If either the Content-Length or Transfer-Encoding headers are found.
 * @throws IllegalArgumentException If the response is null.
 */
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(response, "HTTP response");
    if (this.overwrite) {
        response.removeHeaders(HTTP.TRANSFER_ENCODING);
        response.removeHeaders(HTTP.CONTENT_LEN);
    } else {
        if (response.containsHeader(HTTP.TRANSFER_ENCODING)) {
            throw new ProtocolException("Transfer-encoding header already present");
        }
        if (response.containsHeader(HTTP.CONTENT_LEN)) {
            throw new ProtocolException("Content-Length header already present");
        }
    }
    final ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    final HttpEntity entity = response.getEntity();
    if (entity != null) {
        final long len = entity.getContentLength();
        if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
            response.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else if (len >= 0) {
            response.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }
        // Specify a content type if known
        if (entity.getContentType() != null && !response.containsHeader(
                HTTP.CONTENT_TYPE )) {
            response.addHeader(entity.getContentType());
        }
        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !response.containsHeader(
                HTTP.CONTENT_ENCODING)) {
            response.addHeader(entity.getContentEncoding());
        }
    } else {
        final int status = response.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_NO_CONTENT
                && status != HttpStatus.SC_NOT_MODIFIED
                && status != HttpStatus.SC_RESET_CONTENT) {
            response.addHeader(HTTP.CONTENT_LEN, "0");
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:50,代码来源:ResponseContent.java


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