Пример #1
0
 private String readEntityAsString(HttpEntity entity) throws IOException {
   if (entity == null) {
     throw new IOException("HTTP entity may not be null");
   }
   InputStream instream = entity.getContent();
   if (instream == null) {
     return null;
   }
   try {
     if (entity.getContentLength() > Integer.MAX_VALUE) {
       throw new IOException("HTTP entity too large");
     }
     int i = (int) entity.getContentLength();
     if (i < 0) {
       i = 4096;
     }
     if (entity.getContentEncoding() != null
         && entity.getContentEncoding().getValue().equals("gzip")) {
       instream = new GZIPInputStream(instream);
     }
     Reader reader = new InputStreamReader(instream, HTTP.UTF_8);
     CharArrayBuffer buffer = new CharArrayBuffer(i);
     char[] tmp = new char[1024];
     int l;
     while ((l = reader.read(tmp)) != -1) {
       buffer.append(tmp, 0, l);
     }
     return buffer.toString();
   } finally {
     instream.close();
   }
 }
 /**
  * @param response
  * @param context
  * @throws HttpException
  * @throws IOException
  */
 public void process(final HttpResponse response, final HttpContext context)
     throws HttpException, IOException {
   final HttpEntity entity = response.getEntity();
   if (null != entity) {
     final Header encoding = entity.getContentEncoding();
     if (null != encoding) {
       for (HeaderElement codec : encoding.getElements()) {
         if (codec.getName().equalsIgnoreCase("gzip")) {
           response.setEntity(new GzipDecompressingEntity(response.getEntity()));
           return;
         }
       }
     }
   }
 }
Пример #3
0
 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;
         }
       }
     }
   }
 }
 @Override
 public Header getContentEncoding() {
   return delegate.getContentEncoding();
 }