org.apache.http.client.entity.DeflateDecompressingEntity Java Examples
The following examples show how to use
org.apache.http.client.entity.DeflateDecompressingEntity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApacheHttpRequester.java From algoliasearch-client-java-2 with MIT License | 6 votes |
private static HttpEntity handleCompressedEntity(org.apache.http.HttpEntity entity) { Header contentEncoding = entity.getContentEncoding(); if (contentEncoding != null) for (HeaderElement e : contentEncoding.getElements()) { if (Defaults.CONTENT_ENCODING_GZIP.equalsIgnoreCase(e.getName())) { return new GzipDecompressingEntity(entity); } if (Defaults.CONTENT_ENCODING_DEFLATE.equalsIgnoreCase(e.getName())) { return new DeflateDecompressingEntity(entity); } } return entity; }
Example #2
Source File: ProxyServlet.java From cloud-connectivityproxy with Apache License 2.0 | 6 votes |
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); } } } } }
Example #3
Source File: HTTPSession.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); if (entity != null) { Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (HeaderElement h : codecs) { if (h.getName().equalsIgnoreCase("deflate")) { response.setEntity(new DeflateDecompressingEntity(response.getEntity())); return; } } } } }
Example #4
Source File: HttpSendClient.java From PoseidonX with Apache License 2.0 | 5 votes |
private String uncompress(HttpResponse httpResponse) throws ParseException, IOException { int ret = httpResponse.getStatusLine().getStatusCode(); if (!isOK(ret)) { return null; } // Read the contents String respBody = null; HttpEntity entity = httpResponse.getEntity(); String charset = EntityUtils.getContentCharSet(entity); if (charset == null) { charset = "UTF-8"; } // "Content-Encoding" Header contentEncodingHeader = entity.getContentEncoding(); if (contentEncodingHeader != null) { String contentEncoding = contentEncodingHeader.getValue(); if (contentEncoding.contains("gzip")) { respBody = EntityUtils.toString(new GzipDecompressingEntity(entity), charset); } else if (contentEncoding.contains("deflate")) { respBody = EntityUtils.toString(new DeflateDecompressingEntity(entity), charset); } } else { // "Content-Type" Header contentTypeHeader = entity.getContentType(); if (contentTypeHeader != null) { String contentType = contentTypeHeader.getValue(); if (contentType != null) { if (contentType.startsWith("application/x-gzip-compressed")) { respBody = EntityUtils.toString(new GzipDecompressingEntity(entity), charset); } else if (contentType.startsWith("application/x-deflate")) { respBody = EntityUtils.toString(new DeflateDecompressingEntity(entity), charset); } } } } return respBody; }