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


Java GzipDecompressingEntity類代碼示例

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


GzipDecompressingEntity類屬於org.apache.http.client.entity包,在下文中一共展示了GzipDecompressingEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildHttpClient

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
public static CloseableHttpClient buildHttpClient() {
    CloseableHttpClient httpClient = HttpClients.custom()
            .addInterceptorFirst((HttpRequestInterceptor) (request, context) -> {
                if (!request.containsHeader("Accept-Encoding")) {
                    request.addHeader("Accept-Encoding", "gzip");
                }
            }).addInterceptorFirst((HttpResponseInterceptor) (response1, context) -> {
                HttpEntity entity = response1.getEntity();
                if (entity != null) {
                    Header ceHeader = entity.getContentEncoding();
                    if (ceHeader != null) {
                        HeaderElement[] codecs = ceHeader.getElements();
                        for (HeaderElement codec : codecs) {
                            if (codec.getName().equalsIgnoreCase("gzip")) {
                                response1.setEntity(
                                        new GzipDecompressingEntity(response1.getEntity()));
                                return;
                            }
                        }
                    }
                }
            }).build();

    return httpClient;
}
 
開發者ID:jwboardman,項目名稱:whirlpool,代碼行數:26,代碼來源:HttpClientHelper.java

示例2: testContentEncodingRequestParameter

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
@Test
public void testContentEncodingRequestParameter() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    final StringEntity original = new StringEntity("encoded stuff");
    original.setContentEncoding("GZip");
    response.setEntity(original);

    final RequestConfig config = RequestConfig.custom()
            .setDecompressionEnabled(false)
            .build();

    final HttpContext context = new BasicHttpContext();
    context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);

    final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
    interceptor.process(response, context);
    final HttpEntity entity = response.getEntity();
    Assert.assertNotNull(entity);
    Assert.assertFalse(entity instanceof GzipDecompressingEntity);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:21,代碼來源:TestResponseContentEncoding.java

示例3: initClient

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
private HttpClient initClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    client.addRequestInterceptor((request, context) -> {
        if (!request.containsHeader(ACCEPT_ENCODING)) {
            request.addHeader(ACCEPT_ENCODING, GZIP);
        }
    });

    client.addResponseInterceptor((response, context) -> {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            Header header = entity.getContentEncoding();
            if (header != null) {
                HeaderElement[] elements = header.getElements();
                for (int i = 0; i < elements.length; i++) {
                    if (elements[i].getName().equalsIgnoreCase(GZIP)) {
                        response.setEntity(
                                new GzipDecompressingEntity(response.getEntity()));
                        return;
                    }
                }
            }
        }
    });
    return client;
}
 
開發者ID:staliang,項目名稱:ymaps4j,代碼行數:27,代碼來源:GZipHttpClient.java

示例4: process

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
@Override
public void process(HttpResponse response, HttpContext context)
		throws HttpException, IOException {
	HttpEntity entity = response.getEntity();
	if (entity != null) {
		Header ceheader = entity.getContentEncoding();
		if (ceheader != null) {
			HeaderElement[] codecs = ceheader.getElements();
			for (int i = 0; i < codecs.length; i++) {
				if (codecs[i].getName().equalsIgnoreCase("gzip")) {
					response.setEntity(new GzipDecompressingEntity(
							response.getEntity()));
					return;
				}
			}
		}
	}
}
 
開發者ID:mondo-project,項目名稱:mondo-integration,代碼行數:19,代碼來源:GZipResponseInterceptor.java

示例5: getResponseString

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
public static String getResponseString(HttpResponse response) {
	if (response == null) {
		return null;
	}

	try {
		HttpEntity entity = response.getEntity();
		Header contentEncoding = entity.getContentEncoding();
		if (contentEncoding != null) {
			if (contentEncoding.getValue().toLowerCase(Locale.getDefault())
					.contains("gzip")) {
				GzipDecompressingEntity gzipEntity = new GzipDecompressingEntity(
						entity);
				return EntityUtils.toString(gzipEntity);
			}
		}
		return EntityUtils.toString(entity);
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:coodoing,項目名稱:dataasync,代碼行數:23,代碼來源:HttpHandler.java

示例6: process

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
  HttpEntity entity = response.getEntity();
  if (entity != null) {
    Header ceheader = entity.getContentEncoding();
    if (ceheader != null) {
      HeaderElement[] codecs = ceheader.getElements();
      for (int i = 0; i < codecs.length; i++) {
        if (codecs[i].getName().equalsIgnoreCase("gzip")) {
          response.setEntity(
              new GzipDecompressingEntity(response.getEntity()));
          return;
        }
      }
    }
  }
}
 
開發者ID:Idilia,項目名稱:idilia-java-sdk,代碼行數:18,代碼來源:GzipInterceptors.java

示例7: process

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext)
		throws HttpException, IOException
{
	HttpEntity entity = httpResponse.getEntity();
	if (entity != null)
	{
		Header ceheader = entity.getContentEncoding();
		if (ceheader != null)
		{
			HeaderElement[] codecs = ceheader.getElements();
			for (int i = 0; i < codecs.length; i++)
			{
				if (codecs[i].getName().equalsIgnoreCase("gzip"))
				{
					httpResponse.setEntity(new GzipDecompressingEntity(
							httpResponse.getEntity()));
					return;
				}
			}
		}
	}
}
 
開發者ID:Esquive,項目名稱:iticrawler,代碼行數:24,代碼來源:GzipEncodedResponseInterceptor.java

示例8: postJSON

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
public JSONObject postJSON() throws JSONException, NForumException, IOException{
       HttpResponse response = httpClient.execute(httpPost);
	int statusCode = response.getStatusLine().getStatusCode();
	if (statusCode != 200)
		throw new NForumException(NForumException.EXCEPTION_NETWORK + ":" + statusCode);
	Header header = response.getEntity().getContentEncoding();
	if (header != null) {
		for (HeaderElement element : header.getElements()) {
			if (element.getName().equalsIgnoreCase("gzip")) {
				response.setEntity(new GzipDecompressingEntity(response.getEntity()));
				break;
			}
		}
	}
	String result = ResponseProcessor.getStringFromResponse(response);
	httpPost.abort();
	
	JSONObject json = new JSONObject(result);
	if(json.has("msg")){
		throw new NForumException(json.getString("msg"));
	}
	return json;
}
 
開發者ID:dss886,項目名稱:nForumSDK,代碼行數:24,代碼來源:PostMethod.java

示例9: getJSON

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
public JSONObject getJSON() throws JSONException, NForumException, IOException{
       HttpResponse response = httpClient.execute(httpGet);
	
	int statusCode = response.getStatusLine().getStatusCode();
	if (statusCode != 200)
		throw new NForumException(NForumException.EXCEPTION_NETWORK + ":" + statusCode);
	Header header = response.getEntity().getContentEncoding();
	if (header != null) {
		for (HeaderElement element : header.getElements()) {
			if (element.getName().equalsIgnoreCase("gzip")) {
				response.setEntity(new GzipDecompressingEntity(response.getEntity()));
				break;
			}
		}
	}
	String result = ResponseProcessor.getStringFromResponse(response);
	httpGet.abort();
	
	JSONObject json = new JSONObject(result);
	if(json.has("msg")){
		throw new NForumException(json.getString("msg"));
	}
	return json;
}
 
開發者ID:dss886,項目名稱:nForumSDK,代碼行數:25,代碼來源:GetMethod.java

示例10: process

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
@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;
                }
            }
        }
    }
}
 
開發者ID:polyglot-mark,項目名稱:salesforce-plugin,代碼行數:21,代碼來源:HttpCompressionResponseInterceptor.java

示例11: handleContentEncoding

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
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);
				}
			}
		}
	}
}
 
開發者ID:SAP,項目名稱:cloud-connectivityproxy,代碼行數:26,代碼來源:ProxyServlet.java

示例12: getHttpResponse

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
public HttpResponse getHttpResponse(String url) throws ClientProtocolException, IOException
{
    HttpResponse response = null;
    HttpGet get = new HttpGet(url);
    get.addHeader("Accept", "text/html");
    get.addHeader("Accept-Charset", "utf-8");
    get.addHeader("Accept-Encoding", "gzip");
    get.addHeader("Accept-Language", "en-US,en");
    int uai = rand.nextInt() % userAgents.size();
    if (uai < 0)
    {
        uai = -uai;
    }
    get.addHeader("User-Agent", userAgents.get(uai));
    response = getHttpClient().execute(get);
    HttpEntity entity = response.getEntity();
    Header header = entity.getContentEncoding();
    if (header != null)
    {
        HeaderElement[] codecs = header.getElements();
        for (int i = 0; i < codecs.length; i++)
        {
            if (codecs[i].getName().equalsIgnoreCase("gzip"))
            {
                response.setEntity(new GzipDecompressingEntity(entity));
            }
        }
    }
    return response;

}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:32,代碼來源:HttpFactory.java

示例13: process

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的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

示例14: handleCompressedEntity

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的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

示例15: createGzipResponseInterceptor

import org.apache.http.client.entity.GzipDecompressingEntity; //導入依賴的package包/類
/**
 * If gzip is enabled, this will decode things.
 * @return 
 */
private HttpResponseInterceptor createGzipResponseInterceptor()
{
  return new HttpResponseInterceptor() 
  {
    @Override
    public void process( HttpResponse response, HttpContext context ) 
      throws HttpException, IOException 
    {
      //..get the entity
      final HttpEntity entity = response.getEntity();
      if ( entity == null )
        return;

      //..Get any content encoding headers
      final Header ceHeader = entity.getContentEncoding();
      if ( ceHeader == null )
        return;

      //..Get any entries
      HeaderElement[] codecs = ceHeader.getElements();

      //..See if one is marked as gzip 
      for ( final HeaderElement codec : codecs ) 
      {
        if ( codec.getName().equalsIgnoreCase( "gzip" )) 
        {
          //..Hey, it's gzip! decompress the entity 
          response.setEntity( new GzipDecompressingEntity( response.getEntity()));

          //..Done with this ish.
          return;
        }
      }
    }
  };
}
 
開發者ID:SixArmDonkey,項目名稱:aerodrome-for-jet,代碼行數:41,代碼來源:APIHttpClient.java


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