本文整理汇总了Java中org.apache.http.HttpEntity.consumeContent方法的典型用法代码示例。如果您正苦于以下问题:Java HttpEntity.consumeContent方法的具体用法?Java HttpEntity.consumeContent怎么用?Java HttpEntity.consumeContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpEntity
的用法示例。
在下文中一共展示了HttpEntity.consumeContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: endEntityViaReflection
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public static void endEntityViaReflection(HttpEntity entity) {
if (entity instanceof HttpEntityWrapper) {
Field f = null;
try {
for (Field ff : HttpEntityWrapper.class.getDeclaredFields()) {
if (ff.getName().equals("wrappedEntity")) {
f = ff;
break;
}
}
if (f != null) {
f.setAccessible(true);
HttpEntity wrapped = (HttpEntity) f.get(entity);
if (wrapped != null) {
wrapped.consumeContent();
}
}
} catch (Throwable t) {
Log.e(LOG_TAG, "wrappedEntity consume", t);
}
}
}
示例2: endEntityViaReflection
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
* This horrible hack is required on Android, due to implementation of BasicManagedEntity, which
* doesn't chain call consumeContent on underlying wrapped HttpEntity
*
* @param entity HttpEntity, may be null
*/
public static void endEntityViaReflection(HttpEntity entity) {
if (entity instanceof HttpEntityWrapper) {
try {
Field f = null;
Field[] fields = HttpEntityWrapper.class.getDeclaredFields();
for (Field ff : fields) {
if (ff.getName().equals("wrappedEntity")) {
f = ff;
break;
}
}
if (f != null) {
f.setAccessible(true);
HttpEntity wrapped = (HttpEntity) f.get(entity);
if (wrapped != null) {
wrapped.consumeContent();
}
}
} catch (Throwable t) {
Log.e(LOG_TAG, "wrappedEntity consume", t);
}
}
}
示例3: httpPush
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
private static String httpPush (ArrayList<NameValuePair> nameValuePairs,String action) throws Exception {
HttpPost httppost = new HttpPost(FLOWZR_API_URL + nsString + "/" + action + "/");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
HttpResponse response;
String strResponse;
response = http_client.execute(httppost);
HttpEntity entity = response.getEntity();
int code = response.getStatusLine().getStatusCode();
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
strResponse = reader.readLine();
entity.consumeContent();
if (code!=200) {
throw new Exception(Html.fromHtml(strResponse).toString());
}
return strResponse;
}
示例4: entityToBytes
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/** Reads the contents of HttpEntity into a byte[]. */
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
PoolingByteArrayOutputStream bytes =
new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
byte[] buffer = null;
try {
InputStream in = entity.getContent();
if (in == null) {
throw new ServerError();
}
buffer = mPool.getBuf(1024);
int count;
while ((count = in.read(buffer)) != -1) {
bytes.write(buffer, 0, count);
}
return bytes.toByteArray();
} finally {
try {
// Close the InputStream and release the resources by "consuming the content".
entity.consumeContent();
} catch (IOException e) {
// This can happen if there was an exception above that left the entity in
// an invalid state.
VolleyLog.v("Error occured when calling consumingContent");
}
mPool.returnBuf(buffer);
bytes.close();
}
}
示例5: entityToBytes
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
* Reads the contents of HttpEntity into a byte[].
*/
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
byte[] buffer = null;
try {
InputStream in = entity.getContent();
if (in == null) {
throw new ServerError();
}
buffer = mPool.getBuf(1024);
int count;
while ((count = in.read(buffer)) != -1) {
bytes.write(buffer, 0, count);
}
return bytes.toByteArray();
} finally {
try {
// Close the InputStream and release the resources by "consuming the content".
entity.consumeContent();
} catch (IOException e) {
// This can happen if there was an exception above that left the entity in
// an invalid state.
VolleyLog.v("Error occured when calling consumingContent");
}
mPool.returnBuf(buffer);
bytes.close();
}
}
示例6: entityToBytes
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(this.mPool, (int) entity.getContentLength());
byte[] buffer = null;
try {
InputStream in = entity.getContent();
if (in == null) {
throw new ServerError();
}
buffer = this.mPool.getBuf(1024);
while (true) {
int count = in.read(buffer);
if (count == -1) {
break;
}
bytes.write(buffer, 0, count);
}
byte[] toByteArray = bytes.toByteArray();
return toByteArray;
} finally {
try {
entity.consumeContent();
} catch (IOException e) {
VolleyLog.v("Error occured when calling consumingContent", new Object[0]);
}
this.mPool.returnBuf(buffer);
bytes.close();
}
}
示例7: pullDelete
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public static void pullDelete(long last_sync_ts) throws Exception {
String url=FLOWZR_API_URL + nsString + "/delete/?last_sync_ts=" + last_sync_ts ;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = http_client.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
reader = new JsonReader(new InputStreamReader(is, "UTF-8"));
reader.beginObject();
readDelete(reader);
httpEntity.consumeContent();
}
示例8: entityToBytes
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
* Reads the contents of HttpEntity into a byte[].
*/
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
PoolingByteArrayOutputStream bytes =
new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
byte[] buffer = null;
try {
InputStream in = entity.getContent();
if (in == null) {
throw new ServerError();
}
buffer = mPool.getBuf(1024);
int count;
while ((count = in.read(buffer)) != -1) {
bytes.write(buffer, 0, count);
}
return bytes.toByteArray();
} finally {
try {
// Close the InputStream and release the resources by "consuming the content".
entity.consumeContent();
} catch (IOException e) {
// This can happen if there was an exception above that left the entity in
// an invalid state.
VolleyLog.v("Error occured when calling consumingContent");
}
mPool.returnBuf(buffer);
bytes.close();
}
}
示例9: getJSONFromUrl
import org.apache.http.HttpEntity; //导入方法依赖的package包/类
public static <T> int getJSONFromUrl(String url,String tableName, Class<T> clazz,long last_sync_ts) throws IOException, JSONException, Exception {
if (url==null) {
return 0;
}
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Cookie","[email protected]:False:185804764220139124118");
HttpResponse httpResponse = http_client.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
// All the work is done for you here :)
String jsonContent = EntityUtils.toString(httpEntity);
// Create a Reader from String
Reader stringReader = new StringReader(jsonContent);
//is = httpEntity.getContent();
reader = new JsonReader(stringReader);
reader.setLenient(true);
reader.beginObject();
int i = readMessage(reader, tableName, clazz, last_sync_ts);
httpEntity.consumeContent();
return i;
}