コード例 #1
0
ファイル: YammerHttpClient.java プロジェクト: sxend/yammer4j
 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();
   }
 }
コード例 #2
0
 /**
  * @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
ファイル: HTTPSession.java プロジェクト: msdsoftware/thredds
 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;
         }
       }
     }
   }
 }
コード例 #4
0
 @Override
 public Header getContentEncoding() {
   return delegate.getContentEncoding();
 }