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


Java HttpEntity.getContentEncoding方法代码示例

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


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

示例1: transformRequest

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
private static Request transformRequest(HttpRequest request) {
  Request.Builder builder = new Request.Builder();

  RequestLine requestLine = request.getRequestLine();
  String method = requestLine.getMethod();
  builder.url(requestLine.getUri());

  String contentType = null;
  for (Header header : request.getAllHeaders()) {
    String name = header.getName();
    if ("Content-Type".equalsIgnoreCase(name)) {
      contentType = header.getValue();
    } else {
      builder.header(name, header.getValue());
    }
  }

  RequestBody body = null;
  if (request instanceof HttpEntityEnclosingRequest) {
    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
    if (entity != null) {
      // Wrap the entity in a custom Body which takes care of the content, length, and type.
      body = new HttpEntityBody(entity, contentType);

      Header encoding = entity.getContentEncoding();
      if (encoding != null) {
        builder.header(encoding.getName(), encoding.getValue());
      }
    } else {
      body = Util.EMPTY_REQUEST;
    }
  }
  builder.method(method, body);

  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:OkApacheClient.java

示例2: getContentIsGzip

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public static boolean getContentIsGzip(final HttpEntity entity) throws ParseException {
	boolean gzip = false;
	if (entity.getContentEncoding() != null) {
		HeaderElement values[] = entity.getContentEncoding().getElements();
		for (HeaderElement e : values) {
			gzip = e.getName().equals("gzip");
			if(gzip) break;
		}
	}
	return gzip;
}
 
开发者ID:isuhao,项目名称:QMark,代码行数:12,代码来源:ClientMultipartFormPost.java

示例3: process

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
 * 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());
                }
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:ResponseContentEncoding.java

示例4: load

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
 * load the content of this page from a fetched HttpEntity.
 * @param entity HttpEntity
 * @param maxBytes The maximum number of bytes to read
 * @throws Exception when load fails
 */
public void load(HttpEntity entity, int maxBytes) throws Exception {
    contentType = null;
    Header type = entity.getContentType();
    if (type != null) {
        contentType = type.getValue();
    }
    contentEncoding = null;
    Header encoding = entity.getContentEncoding();
    if (encoding != null) {
        contentEncoding = encoding.getValue();
    }

    Charset charset = ContentType.getOrDefault(entity).getCharset();
    if (charset != null) {
        contentCharset = charset.displayName();
    }else {
        contentCharset = Charset.defaultCharset().displayName();
    }

    contentData = toByteArray(entity, maxBytes);
}
 
开发者ID:doubleview,项目名称:fastcrawler,代码行数:28,代码来源:Page.java

示例5: getEncoding

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
private static Charset getEncoding(HttpEntity entity) {
    if (entity.getContentEncoding() != null) {
        String value = entity.getContentEncoding().getValue();
        if (value != null) {
            try {
                return Charset.forName(value);
            } catch (RuntimeException e) {
                // use the default charset!
                LOGGER.debug("Unsupported charset: {}", value, e);
            }
        }
    }
    return StandardCharsets.UTF_8;
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:15,代码来源:HttpClient.java

示例6: process

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public void process(HttpResponse response, HttpContext context) {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Header encoding = entity.getContentEncoding();
        if (encoding != null) {
            for (HeaderElement element : encoding.getElements()) {
                if (element.getName().equalsIgnoreCase(AsyncHttpClient.ENCODING_GZIP)) {
                    response.setEntity(new AsyncHttpClient$InflatingEntity(entity));
                    return;
                }
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:AsyncHttpClient$2.java

示例7: a

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public static InputStream a(HttpEntity httpEntity) {
    InputStream content = httpEntity.getContent();
    if (content == null) {
        return content;
    }
    Header contentEncoding = httpEntity.getContentEncoding();
    if (contentEncoding == null) {
        return content;
    }
    String value = contentEncoding.getValue();
    if (value == null) {
        return content;
    }
    return value.contains(AsyncHttpClient.ENCODING_GZIP) ? new GZIPInputStream(content) : content;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:16,代码来源:b.java

示例8: afterDoCap

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {

    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        Span span = (Span) context.get(InvokeChainConstants.PARAM_SPAN_KEY);
        SlowOperContext slowOperContext = new SlowOperContext();
        if (Throwable.class.isAssignableFrom(args[0].getClass())) {

            Throwable e = (Throwable) args[0];
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, e.toString());

        }
        else {
            HttpResponse response = (HttpResponse) args[0];

            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getResponHeaders(response));
            HttpEntity entity = response.getEntity();
            // 由于存在读取失败和无法缓存的大entity会使套壳失败,故此处添加如下判断
            if (BufferedHttpEntity.class.isAssignableFrom(entity.getClass())) {
                Header header = entity.getContentEncoding();
                String encoding = header == null ? "utf-8" : header.getValue();
                slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, getHttpEntityContent(entity, encoding));
            }
            else {
                slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY,
                        "HttpEntityWrapper failed! Maybe HTTP entity too large to be buffered in memory");
            }
        }

        Object params[] = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap",
                span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
    }

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:36,代码来源:ApacheHttpClientAdapter.java

示例9: handleCompressedEntity

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
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;
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:16,代码来源:HTTPCUtil.java

示例10: process

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    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");
            }
        }
        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        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:lamsfoundation,项目名称:lams,代码行数:46,代码来源:RequestContent.java

示例11: process

import org.apache.http.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 {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    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");
        }
    }
    ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        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 {
        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:lamsfoundation,项目名称:lams,代码行数:52,代码来源:ResponseContent.java

示例12: apply

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
@Override
public ClientResponse apply(final ClientRequest clientRequest) throws ProcessingException {
    final HttpUriRequest request = this.toUriHttpRequest(clientRequest);
    final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(clientRequest.getHeaders(), request);

    try {
        final CloseableHttpResponse response;
        response = client.execute(new HttpHost(request.getURI().getHost(), request.getURI().getPort(), request.getURI().getScheme()), request, new BasicHttpContext(context));
        HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, clientRequest.getHeaders(), this.getClass().getName());

        final Response.StatusType status = response.getStatusLine().getReasonPhrase() == null
                ? Statuses.from(response.getStatusLine().getStatusCode())
                : Statuses.from(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());

        final ClientResponse responseContext = new ClientResponse(status, clientRequest);
        final List<URI> redirectLocations = context.getRedirectLocations();
        if(redirectLocations != null && !redirectLocations.isEmpty()) {
            responseContext.setResolvedRequestUri(redirectLocations.get(redirectLocations.size() - 1));
        }

        final Header[] respHeaders = response.getAllHeaders();
        final MultivaluedMap<String, String> headers = responseContext.getHeaders();
        for(final Header header : respHeaders) {
            final String headerName = header.getName();
            List<String> list = headers.get(headerName);
            if(list == null) {
                list = new ArrayList<>();
            }
            list.add(header.getValue());
            headers.put(headerName, list);
        }

        final HttpEntity entity = response.getEntity();

        if(entity != null) {
            if(headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
                headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
            }

            final Header contentEncoding = entity.getContentEncoding();
            if(headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) {
                headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue());
            }
        }
        responseContext.setEntityStream(this.toInputStream(response));
        return responseContext;
    }
    catch(final Exception e) {
        throw new ProcessingException(e);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:52,代码来源:HttpComponentsConnector.java

示例13: run

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
@Override
public void run() {

    try (final CloseableHttpClient httpClient = createMinimal()) {

        CloseableHttpResponse response = httpClient.execute(new HttpGet(APP_VERSION_URL));
        StatusLine statusLine = response.getStatusLine();

        if (statusLine.getStatusCode() != 200) {
            return;
        }

        HttpEntity entity = response.getEntity();
        InputStream content = entity.getContent();
        Header encoding = entity.getContentEncoding();
        String enc = encoding == null ? "UTF-8" : encoding.getValue();

        final String targetVersion = IOUtils.toString(content, enc)
                .trim()
                .replace("v.", "");

        if (Config.APP_VERSION.compareTo(new Version(targetVersion)) >= 0) {
            return;
        }

        response = httpClient.execute(new HttpGet(DOWNLOAD_APP_PATH_URL));
        statusLine = response.getStatusLine();

        if (statusLine.getStatusCode() != 200) {
            return;
        }

        entity = response.getEntity();
        content = entity.getContent();
        encoding = entity.getContentEncoding();
        enc = encoding == null ? "UTF-8" : encoding.getValue();

        final String targetLink = IOUtils.toString(content, enc).trim();

        Platform.runLater(() -> {

            final JFXApplication jfxApplication = JFXApplication.getInstance();
            final HostServices hostServices = jfxApplication.getHostServices();

            final Hyperlink hyperlink = new Hyperlink(Messages.CHECK_NEW_VERSION_DIALOG_HYPERLINK + targetLink);
            hyperlink.setOnAction(event -> hostServices.showDocument(targetLink));

            final Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle(Messages.CHECK_NEW_VERSION_DIALOG_TITLE);
            alert.setHeaderText(Messages.CHECK_NEW_VERSION_DIALOG_HEADER_TEXT + targetVersion);

            final DialogPane dialogPane = alert.getDialogPane();
            dialogPane.setContent(hyperlink);

            alert.show();
        });

    } catch (final IOException e) {
        LOGGER.warning(e);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:62,代码来源:CheckNewVersionTask.java


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