Java Code Examples for org.apache.http.HttpEntity#isStreaming()

The following examples show how to use org.apache.http.HttpEntity#isStreaming() . These examples are extracted from open source projects. 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
private static ReadableByteChannel wrap(final InputStream is, final HttpEntity he,
        final Content c, final double contentLength){
    return new ReadableByteChannel() {
        double total = 0;
        @Override public int read(ByteBuffer dst) throws IOException {
            byte[]b=new byte[dst.capacity()];
            int r = is.read(b); 
            //this sleep is just to slow down update to see, if the UI is working or not !
            // NU's update is very very very fast
            //try{Thread.sleep(1000);}catch(Exception a){}
            dst.put(b,0,r); total+=r; c.setProgress(total/contentLength);
            return r;
        }
        @Override public boolean isOpen() {
            return he.isStreaming();
        }
        @Override public void close() throws IOException {
            is.close();
        }
    };
}
 
Example 2
public void closeResponseEntity(HttpResponse response) {
  if (response == null)
    return;
  HttpEntity entity = response.getEntity();
  if (entity != null && entity.isStreaming())
    try {
      entity.getContent().close();
    } catch (IOException e) {
      LOG.error(formatErrorMsg("close response entity", e));
    }
}
 
Example 3
Source Project: bce-sdk-java   File: BceHttpResponse.java    License: Apache License 2.0 5 votes vote down vote up
public BceHttpResponse(CloseableHttpResponse httpResponse) throws IOException {
    this.httpResponse = httpResponse;
    HttpEntity entity = httpResponse.getEntity();
    if (entity != null && entity.isStreaming()) {
        this.content = entity.getContent();
    }
}
 
Example 4
Source Project: galaxy-sdk-java   File: SdsTHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore that doesn't
 * have a consume.
 */
private static void consume(final HttpEntity entity) throws IOException {
  if (entity == null) {
    return;
  }
  if (entity.isStreaming()) {
    InputStream instream = entity.getContent();
    if (instream != null) {
      instream.close();
    }
  }
}
 
Example 5
/**
 * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore that doesn't
 * have a consume.
 */
private static void consume(final HttpEntity entity) throws IOException {
  if (entity == null) {
    return;
  }
  if (entity.isStreaming()) {
    InputStream instream = entity.getContent();
    if (instream != null) {
      instream.close();
    }
  }
}
 
Example 6
Source Project: galaxy-sdk-java   File: BaseClient.java    License: Apache License 2.0 5 votes vote down vote up
protected static void closeResponseEntity(HttpResponse response) {
  if (response == null)
    return;
  HttpEntity entity = response.getEntity();
  if (entity != null && entity.isStreaming())
    try {
      entity.getContent().close();
    } catch (IOException e) {
      LOG.error("close response entity", e);
    }
}
 
Example 7
/**
 * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore that doesn't
 * have a consume.
 */
private static void consume(final HttpEntity entity) throws IOException {
  if (entity == null) {
    return;
  }
  if (entity.isStreaming()) {
    InputStream instream = entity.getContent();
    if (instream != null) {
      instream.close();
    }
  }
}
 
Example 8
Source Project: galaxy-sdk-java   File: TalosHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore that doesn't
 * have a consume.
 */
private static void consume(final HttpEntity entity) throws IOException {
  if (entity == null) {
    return;
  }
  if (entity.isStreaming()) {
    InputStream instream = entity.getContent();
    if (instream != null) {
      instream.close();
    }
  }
}
 
Example 9
Source Project: galaxy-sdk-java   File: THttpClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore
 * that doesn't have a consume.
 */
private static void consume(final HttpEntity entity) throws IOException {
    if (entity == null) {
        return;
    }
    if (entity.isStreaming()) {
        InputStream instream = entity.getContent();
        if (instream != null) {
            instream.close();
        }
    }
}
 
Example 10
Source Project: RoboZombie   File: EntityUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the entity content is fully consumed and the content stream, if exists,
 * is closed.
 *
 * @param entity
 * @throws IOException if an error occurs reading the input stream
 *
 * @since 4.1
 */
public static void consume(final HttpEntity entity) throws IOException {
    if (entity == null) {
        return;
    }
    if (entity.isStreaming()) {
        InputStream instream = entity.getContent();
        if (instream != null) {
            instream.close();
        }
    }
}