use of org.apache.http.entity.BufferedHttpEntity in project ThinkAndroid by white-cat.
the class AsyncHttpResponseHandler method sendResponseMessage.
protected void sendResponseMessage(HttpResponse response) {
StatusLine status = response.getStatusLine();
String responseBody = null;
try {
HttpEntity entity = null;
HttpEntity temp = response.getEntity();
if (temp != null) {
entity = new BufferedHttpEntity(temp);
responseBody = EntityUtils.toString(entity, "UTF-8");
}
} catch (IOException e) {
sendFailureMessage(e, (String) null);
}
if (status.getStatusCode() >= 300) {
sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
} else {
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
}
}
use of org.apache.http.entity.BufferedHttpEntity in project RoboZombie by sahan.
the class RequestParamEndpointTest method testBufferedHttpEntity.
/**
* <p>Test for a {@link Request} with a <b>buffered</b> entity.</p>
*
* @since 1.3.0
*/
@Test
public final void testBufferedHttpEntity() throws ParseException, IOException {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/bufferedhttpentity";
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("LICENSE.txt");
InputStream parallelInputStream = classLoader.getResourceAsStream("LICENSE.txt");
BasicHttpEntity bhe = new BasicHttpEntity();
bhe.setContent(parallelInputStream);
stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
requestEndpoint.bufferedHttpEntity(inputStream);
verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(EntityUtils.toString(new BufferedHttpEntity(bhe)))));
}
use of org.apache.http.entity.BufferedHttpEntity in project FastDev4Android by jiangqqlmj.
the class IoUtils method getBitmapData.
/**
* 获取Image图片信息
*
* @return bitmap
*/
public static Bitmap getBitmapData(String imgUrl) {
Bitmap bmp = null;
Log.d(TAG_LISTLOGIC, "get imgage:" + imgUrl);
InputStream inpStream = null;
try {
HttpGet http = new HttpGet(imgUrl);
HttpClient client = new DefaultHttpClient();
HttpResponse response = (HttpResponse) client.execute(http);
HttpEntity httpEntity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);
// 获取数据流
inpStream = bufferedHttpEntity.getContent();
bmp = BitmapFactory.decodeStream(inpStream);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (inpStream != null) {
try {
inpStream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
return bmp;
}
Aggregations