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:com.damytech.HttpConn.AsyncHttpResponseHandler.java

void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;/*from   w w  w.ja  v  a  2 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);
        return;
    }

    if (status.getStatusCode() >= 300) {
        sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
                responseBody);
    } else {
        sendSuccessMessage(status.getStatusCode(), responseBody);
    }
}

From source file:org.apache.abdera2.common.protocol.ClientResponseImpl.java

private HttpEntity getEntity() throws IOException {
    if (buffer == null) {
        HttpEntity entity = response.getEntity();
        if (entity != null)
            buffer = new BufferedHttpEntity(response.getEntity());
    }//from ww  w.ja va 2s  .  c  o  m
    return buffer;
}

From source file:org.example.camera.List14.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    URL myFileUrl = null;//from   ww  w.j  ava2 s.c o m
    try {
        URL url = new URL("http://wheelspotting.com/recent.json");
        URLConnection tc = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));

        String line;
        while ((line = in.readLine()) != null) {
            JSONArray ja = new JSONArray(line);
            Log.i("jsondeal", ja.getString(0));

            for (int i = 0; i < ja.length(); i++) {
                JSONObject jo = (JSONObject) ja.get(i);
                try {
                    myFileUrl = new URL(jo.getString("medium_image"));
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                HttpGet httpRequest = null;
                try {
                    httpRequest = new HttpGet(myFileUrl.toURI());
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
                HttpEntity entity = response.getEntity();
                BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
                InputStream instream = bufHttpEntity.getContent();
                Bitmap bmImg = BitmapFactory.decodeStream(instream);
                listPics.add(bmImg);
                listTitles.add(jo.getString("title"));
                listLargeUrls.add(jo.getString("large_image"));
            }
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    setListAdapter(new EfficientAdapter(this));
}

From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java

private Bitmap loadImageFromURL(String getURL) {

    try {//from  ww  w . java  2s .  com
        URL url = new URL(getURL);

        HttpGet httpRequest = null;
        httpRequest = new HttpGet(url.toURI());
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
        InputStream input = b_entity.getContent();
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        return bitmap;
    } catch (Exception ex) {

        Toast t2 = Toast.makeText(getApplicationContext(), "Image Loading Failed", Toast.LENGTH_LONG);
        t2.setGravity(Gravity.CENTER, 0, 0);
        t2.show();
        return null;
    }
}

From source file:com.qk.applibrary.http.AsyncHttpResponseHandler.java

void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;//from   w w w .  ja  v a 2s .c  o  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() == 200) {
        sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
    } else {
        sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
                responseBody);
    }
}

From source file:cn.caimatou.canting.utils.http.asynchttp.AsyncHttpResponseHandler.java

void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;/*  w w  w.ja  v a  2  s .  com*/
    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);
    }
}

From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java

@SuppressWarnings("unused")
private String reporteds(String path) {

    ExifInterface exif = null;//from  www.j  a v  a 2s .c o  m
    try {
        exif = new ExifInterface(path);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    Matrix matrix = new Matrix();
    if (orientation == 6) {
        matrix.postRotate(90);
    } else if (orientation == 3) {
        matrix.postRotate(180);
    } else if (orientation == 8) {
        matrix.postRotate(270);
    }

    if (path != null) {

        if (path.contains("http")) {
            try {
                URL url = new URL(path);
                HttpGet httpRequest = null;

                httpRequest = new HttpGet(url.toURI());

                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

                HttpEntity entity = response.getEntity();
                BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
                InputStream input = bufHttpEntity.getContent();

                Bitmap bitmap = BitmapFactory.decodeStream(input);
                input.close();
                return getPath(bitmap);
            } catch (MalformedURLException e) {
                Log.e("ImageActivity", "bad url", e);
            } catch (Exception e) {
                Log.e("ImageActivity", "io error", e);
            }
        } else {

            Options options = new Options();
            options.inSampleSize = 2;
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeResource(context.getResources(), srcBgId, options);
            options.inJustDecodeBounds = false;
            options.inSampleSize = calculateInSampleSize(options, w, h);
            Bitmap unbgbtmp = BitmapFactory.decodeResource(context.getResources(), srcBgId, options);
            Bitmap unrlbtmp = ScalingUtilities.decodeFile(path, w, h, ScalingLogic.FIT);
            unrlbtmp.recycle();
            Bitmap rlbtmp = null;
            if (unrlbtmp != null) {
                rlbtmp = ScalingUtilities.createScaledBitmap(unrlbtmp, w, h, ScalingLogic.FIT);
            }
            if (unbgbtmp != null && rlbtmp != null) {
                Bitmap bgbtmp = ScalingUtilities.createScaledBitmap(unbgbtmp, w, h, ScalingLogic.FIT);
                Bitmap newscaledBitmap = ProcessingBitmapTwo(bgbtmp, rlbtmp);
                unbgbtmp.recycle();
                return getPath(newscaledBitmap);
            }
        }
    }
    return path;

}

From source file:org.mozilla.gecko.favicons.LoadFaviconTask.java

private Bitmap downloadFavicon(URI targetFaviconURI) {
    if (targetFaviconURI == null) {
        return null;
    }/*from  w  ww . ja  v  a 2 s .c o  m*/

    // Only get favicons for HTTP/HTTPS.
    String scheme = targetFaviconURI.getScheme();
    if (!"http".equals(scheme) && !"https".equals(scheme)) {
        return null;
    }

    Bitmap image = null;

    // skia decoder sometimes returns null; workaround is to use BufferedHttpEntity
    // http://groups.google.com/group/android-developers/browse_thread/thread/171b8bf35dbbed96/c3ec5f45436ceec8?lnk=raot
    try {
        // Try the URL we were given.
        HttpResponse response = tryDownload(targetFaviconURI);
        if (response == null) {
            return null;
        }

        HttpEntity entity = response.getEntity();
        if (entity == null) {
            return null;
        }

        BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
        InputStream contentStream = null;
        try {
            contentStream = bufferedEntity.getContent();
            image = BitmapUtils.decodeStream(contentStream);
            contentStream.close();
        } finally {
            if (contentStream != null) {
                contentStream.close();
            }
        }
    } catch (Exception e) {
        Log.e(LOGTAG, "Error reading favicon", e);
    }

    return image;
}

From source file:com.cloudmine.api.CMFile.java

private static InputStream extractInputStream(HttpResponse response) throws CreationException {
    if (response == null || response.getEntity() == null)
        return null;
    try {//  www  . j  a  v  a2 s.  c  o  m
        return new BufferedHttpEntity(response.getEntity()).getContent();
    } catch (IOException e) {
        LOG.error("IOException getting response entity contents", e);
        throw new CreationException(e);
    }
}

From source file:net.dahanne.gallery3.client.business.G3Client.java

/**
 * Send the HTTP request to the gallery// w w w. ja v  a2 s. c  om
 * 
 * @param appendToGalleryUrl
 * @param nameValuePairs
 * @param useExistingApiKey
 * @param requestMethod
 * @param file
 * @return the response from the HTTP server
 * @throws G3GalleryException
 */
private String sendHttpRequest(String appendToGalleryUrl, List<NameValuePair> nameValuePairs,
        String requestMethod, File file) throws G3GalleryException {

    logger.debug("appendToGalleryUrl : {} -- nameValuePairs : {} -- requestMethod : {} -- file : {}",
            new Object[] { appendToGalleryUrl, nameValuePairs, requestMethod,
                    file != null ? file.getAbsolutePath() : null });
    String result;

    // do we need to login ? do we have the apikey ?
    if (username != null && existingApiKey == null) {
        // we are inside a call of getApiKey
        if (nameValuePairs != null && nameValuePairs.size() != 0) {
            if (nameValuePairs.get(0).getName().equals("user")) {

            } else {
                existingApiKey = getApiKey();
            }
        } else {
            existingApiKey = getApiKey();
        }
    }

    try {
        HttpEntity responseEntity = requestToResponseEntity(appendToGalleryUrl, nameValuePairs, requestMethod,
                file);
        responseEntity = new BufferedHttpEntity(responseEntity);

        BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
        String line;
        StringBuilder sb = new StringBuilder();
        logger.debug("Beginning reading the response");

        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
        } finally {
            reader.close();
        }
        result = sb.toString();
        logger.debug("result : {}", result);
        logger.debug("Ending reading the response");

    } catch (ClientProtocolException e) {
        throw new G3GalleryException(e.getMessage());
    } catch (IOException e) {
        throw new G3GalleryException(e.getMessage());
    }
    logger.debug("");
    return result;
}