下面列出了org.apache.http.HttpEntity#isStreaming ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
};
}
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));
}
}
public BceHttpResponse(CloseableHttpResponse httpResponse) throws IOException {
this.httpResponse = httpResponse;
HttpEntity entity = httpResponse.getEntity();
if (entity != null && entity.isStreaming()) {
this.content = entity.getContent();
}
}
/**
* 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();
}
}
}
/**
* 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();
}
}
}
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);
}
}
/**
* 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();
}
}
}
/**
* 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();
}
}
}
/**
* 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();
}
}
}
/**
* 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();
}
}
}