當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpEntity.consumeContent方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:AsyncHttpClient.java

示例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);
        }
    }
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:30,代碼來源:AsyncHttpClient.java

示例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;    	    	
  }
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:17,代碼來源:FlowzrSyncEngine.java

示例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();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:BasicNetwork.java

示例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();
    }
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:31,代碼來源:BaseNetwork.java

示例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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:29,代碼來源:BasicNetwork.java

示例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();
  }
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:12,代碼來源:FlowzrSyncEngine.java

示例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();
  }
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:32,代碼來源:DrBasicNetwork.java

示例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;


}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:31,代碼來源:FlowzrSyncEngine.java


注:本文中的org.apache.http.HttpEntity.consumeContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。