Java 类org.apache.http.client.entity.DeflateDecompressingEntity 实例源码

项目:salesforce-plugin    文件:HttpCompressionResponseInterceptor.java   
@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Header contentEncoding = entity.getContentEncoding();
        if (contentEncoding != null) {
            HeaderElement[] codecs = contentEncoding.getElements();
            for (HeaderElement codec : codecs) {
                if (codec.getName().equalsIgnoreCase(GZIP)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    return;
                }
                if (codec.getName().equalsIgnoreCase(DEFLATE)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    return;
                }
            }
        }
    }
}
项目:cloud-connectivityproxy    文件:ProxyServlet.java   
private void handleContentEncoding(HttpResponse response) throws ServletException {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Header contentEncodingHeader = entity.getContentEncoding();
        if (contentEncodingHeader != null) {
            HeaderElement[] codecs = contentEncodingHeader.getElements();
            LOGGER.debug("Content-Encoding in response:");
            for (HeaderElement codec : codecs) {
                String codecname = codec.getName().toLowerCase();
                LOGGER.debug("    => codec: " + codecname);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    return;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    return;
                } else if ("identity".equals(codecname)) {
                    return;
                } else {
                    throw new ServletException("Unsupported Content-Encoding: " + codecname);
                }
            }
        }
    }
}
项目:lams    文件:ResponseContentEncoding.java   
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    HttpEntity entity = response.getEntity();

    // It wasn't a 304 Not Modified response, 204 No Content or similar
    if (entity != null) {
        Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            HeaderElement[] codecs = ceheader.getElements();
            for (HeaderElement codec : codecs) {
                String codecname = codec.getName().toLowerCase(Locale.US);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    if (context != null) context.setAttribute(UNCOMPRESSED, true);  
                    return;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    if (context != null) context.setAttribute(UNCOMPRESSED, true);
                    return;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
        }
    }
}
项目:java-restclient    文件:HTTPCUtil.java   
public static HttpEntity handleCompressedEntity(HttpEntity entity) {
    org.apache.http.Header contentEncoding = entity.getContentEncoding();
    if (contentEncoding != null)
        for (HeaderElement e : contentEncoding.getElements()) {
            if (CONTENT_ENCODING_GZIP.equalsIgnoreCase(e.getName())) {
                return new GzipDecompressingEntity(entity);
            }

            if (CONTENT_ENCODING_DEFLATE.equalsIgnoreCase(e.getName())) {
                return new DeflateDecompressingEntity(entity);
            }
        }

    return entity;
}
项目:remote-files-sync    文件:ResponseContentEncoding.java   
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    final HttpEntity entity = response.getEntity();

    // entity can be null in case of 304 Not Modified, 204 No Content or similar
    // check for zero length entity.
    if (entity != null && entity.getContentLength() != 0) {
        final Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            final HeaderElement[] codecs = ceheader.getElements();
            boolean uncompressed = false;
            for (final HeaderElement codec : codecs) {
                final String codecname = codec.getName().toLowerCase(Locale.ENGLISH);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
            if (uncompressed) {
                response.removeHeaders("Content-Length");
                response.removeHeaders("Content-Encoding");
                response.removeHeaders("Content-MD5");
            }
        }
    }
}
项目:Visit    文件:ResponseContentEncoding.java   
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    final HttpEntity entity = response.getEntity();

    // entity can be null in case of 304 Not Modified, 204 No Content or similar
    // check for zero length entity.
    if (entity != null && entity.getContentLength() != 0) {
        final Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            final HeaderElement[] codecs = ceheader.getElements();
            boolean uncompressed = false;
            for (final HeaderElement codec : codecs) {
                final String codecname = codec.getName().toLowerCase(Locale.ENGLISH);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
            if (uncompressed) {
                response.removeHeaders("Content-Length");
                response.removeHeaders("Content-Encoding");
                response.removeHeaders("Content-MD5");
            }
        }
    }
}
项目:ZTLib    文件:ResponseContentEncoding.java   
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    final HttpEntity entity = response.getEntity();

    // entity can be null in case of 304 Not Modified, 204 No Content or similar
    // check for zero length entity.
    if (entity != null && entity.getContentLength() != 0) {
        final Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            final HeaderElement[] codecs = ceheader.getElements();
            boolean uncompressed = false;
            for (final HeaderElement codec : codecs) {
                final String codecname = codec.getName().toLowerCase(Locale.ENGLISH);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
            if (uncompressed) {
                response.removeHeaders("Content-Length");
                response.removeHeaders("Content-Encoding");
                response.removeHeaders("Content-MD5");
            }
        }
    }
}