Example usage for org.apache.http.entity BufferedHttpEntity BufferedHttpEntity

List of usage examples for org.apache.http.entity BufferedHttpEntity BufferedHttpEntity

Introduction

In this page you can find the example usage for org.apache.http.entity BufferedHttpEntity BufferedHttpEntity.

Prototype

public BufferedHttpEntity(HttpEntity httpEntity) throws IOException 

Source Link

Usage

From source file:org.apache.camel.component.restlet.RestletTestSupport.java

public HttpResponse doExecute(HttpUriRequest method) throws Exception {
    HttpClient client = new DefaultHttpClient();
    try {/*from   w  w w  .j  a  v a 2  s.  co m*/
        HttpResponse response = client.execute(method);
        response.setEntity(new BufferedHttpEntity(response.getEntity()));
        return response;
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:ar.com.colo.rest.test.RestletTestSupport.java

public HttpResponse doExecute(HttpUriRequest method) throws Exception {
    CloseableHttpClient client = HttpClientBuilder.create().build();
    try {//from   www  . j a va2s. co m
        HttpResponse response = client.execute(method);
        response.setEntity(new BufferedHttpEntity(response.getEntity()));
        return response;
    } finally {
        client.close();
    }
}

From source file:com.carelife.cdownloader.core.download.HttpClientImageDownloader.java

@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
    HttpGet httpRequest = new HttpGet(imageUri);
    HttpResponse response = httpClient.execute(httpRequest);
    HttpEntity entity = response.getEntity();
    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
    return bufHttpEntity.getContent();
}

From source file:com.universalimageloader1.core.download.HttpClientImageDownloader.java

@Override
protected InputStream getStreamFromNetwork(URI imageUri, Object extra) {
    try {/*from  www.  j  ava  2  s .c o m*/
        HttpGet httpRequest = new HttpGet(imageUri.toString());
        HttpResponse response = httpClient.execute(httpRequest);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
        return bufHttpEntity.getContent();
    } catch (Exception e) {
        // TODO: handle exception
        return null;

    }
}

From source file:com.fanfou.app.opensource.http.SimpleResponse.java

public SimpleResponse(final HttpResponse response) {
    this.statusLine = response.getStatusLine();
    this.statusCode = this.statusLine.getStatusCode();

    final HttpEntity wrappedHttpEntity = response.getEntity();
    if (wrappedHttpEntity != null) {
        try {//from   w ww  .j  a v  a2  s. c  o m
            this.entity = new BufferedHttpEntity(wrappedHttpEntity);
        } catch (final IOException e) {
            this.entity = null;
        }
    }
}

From source file:com.core.framework.image.universalimageloader.core.download.HttpClientImageDownloader.java

@Override
protected InputStream getStreamFromNetwork(DealUrl imageUri, Object extra) throws IOException {
    HttpGet httpRequest = new HttpGet(imageUri.url);
    HttpResponse response = httpClient.execute(httpRequest);
    HttpEntity entity = response.getEntity();
    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
    return bufHttpEntity.getContent();
}

From source file:com.lurencun.cfuture09.androidkit.http.async.EntityHttpResponseHandler.java

void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;//from  ww w . ja va2  s  .  co m
    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(), response.getEntity());
    }
}

From source file:net.orzo.data.Web.java

/**
 *
 *//*  w  w  w  .  java 2 s .  co  m*/
public String get(String URL) {
    HttpGet httpget = new HttpGet(URL);
    CloseableHttpResponse response = null;
    HttpEntity httpEntity;
    String result = null;

    try {
        response = this.httpClient.execute(httpget);
        httpEntity = response.getEntity();
        if (httpEntity != null) {
            httpEntity = new BufferedHttpEntity(httpEntity);
            result = EntityUtils.toString(httpEntity);
        }

    } catch (IOException e) {
        throw new RuntimeException(e);

    } finally {
        if (response != null) {
            try {
                response.close();
            } catch (IOException e) {
                LOG.warn(String.format("Failed to close response object: %s", e));
            }
        }
    }
    return result;
}

From source file:guru.nidi.ramltester.httpcomponents.HttpComponentsRamlMessage.java

private BufferedHttpEntity buffered(HttpEntity entity) {
    try {//from ww  w. ja  v  a2 s . c  o  m
        return new BufferedHttpEntity(entity);
    } catch (IOException e) {
        throw new RamlCheckerException("Could not read content of entity", e);
    }
}

From source file:com.onemorecastle.util.HttpFetch.java

public static Bitmap fetchBitmap(String imageAddress, int sampleSize)
        throws MalformedURLException, IOException {
    Bitmap bitmap = null;/*from w  w w . jav  a 2  s  .co m*/
    DefaultHttpClient httpclient = null;
    try {
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 2000);
        HttpConnectionParams.setSoTimeout(httpParameters, 5000);
        HttpConnectionParams.setSocketBufferSize(httpParameters, 512);
        HttpGet httpRequest = new HttpGet(URI.create(imageAddress));
        httpclient = new DefaultHttpClient();
        httpclient.setParams(httpParameters);
        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
        InputStream instream = bufHttpEntity.getContent();
        BitmapFactory.Options options = new BitmapFactory.Options();
        //first decode with inJustDecodeBounds=true to check dimensions
        options.inJustDecodeBounds = true;
        options.inSampleSize = sampleSize;
        BitmapFactory.decodeStream(instream, null, options);
        //decode bitmap with inSampleSize set
        options.inSampleSize = calculateInSampleSize(options, MAX_WIDTH, MAX_HEIGHT);
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inDither = true;
        options.inJustDecodeBounds = false;
        //response=(HttpResponse)httpclient.execute(httpRequest);
        //entity=response.getEntity();
        //bufHttpEntity=new BufferedHttpEntity(entity);
        instream = bufHttpEntity.getContent();
        bitmap = BitmapFactory.decodeStream(instream, null, options);
        //close out stuff
        try {
            instream.close();
            bufHttpEntity.consumeContent();
            entity.consumeContent();
        } finally {
            instream = null;
            bufHttpEntity = null;
            entity = null;
        }
    } catch (Exception x) {
        Log.e("HttpFetch.fetchBitmap", imageAddress, x);
    } finally {
        httpclient = null;
    }
    return (bitmap);
}