List of usage examples for org.apache.http.entity BufferedHttpEntity getContentLength
public long getContentLength()
From source file:de.mojadev.ohmmarks.virtuohm.VirtuOhmHTTPHandler.java
private String getResponseText(HttpResponse response) throws IllegalStateException, IOException { BufferedHttpEntity responseEntity = new BufferedHttpEntity(response.getEntity()); int contentLength = (int) responseEntity.getContentLength(); InputStream stream = responseEntity.getContent(); byte buffer[] = new byte[contentLength]; stream.read(buffer, 0, contentLength); return new String(buffer); }
From source file:com.neusou.bioroid.image.ImageLoader.java
public Bitmap loadImage(final String imageUri, boolean immediately) { if (imageUri == null || imageUri.equals("null")) { return null; }//from ww w. ja va2 s.co m final String url; url = imageUri; if (url == null || url.compareTo("null") == 0) { return null; } Bitmap dcached; dcached = mBitmapMap.get(url); if (dcached != null || immediately) { if (dcached == null) { mBitmapMap.remove(url); } return dcached; } URL imageUrl = null; try { imageUrl = new URL(imageUri); } catch (MalformedURLException e) { return null; } File imageDir = new File(mCacheDirectoryPath); String bigInt = computeDigest(url); File cachedImageFile = new File(imageDir, bigInt); String ess = Environment.getExternalStorageState(); boolean canReadImageCacheDir = false; if (ess.equals(Environment.MEDIA_MOUNTED)) { if (!imageDir.canRead()) { boolean createSuccess = false; synchronized (imageDir) { createSuccess = imageDir.mkdirs(); } canReadImageCacheDir = createSuccess && imageDir.canRead(); } canReadImageCacheDir = imageDir.canRead(); if (cachedImageFile.canRead()) { try { Bitmap cachedBitmap = getCachedBitmap(imageUrl, cachedImageFile); if (cachedBitmap != null) { mBitmapMap.put(imageUri, cachedBitmap); return cachedBitmap; } } catch (FileNotFoundException e) { e.printStackTrace(); } } } HttpGet httpRequest = null; try { httpRequest = new HttpGet(imageUrl.toURI()); } catch (URISyntaxException e) { e.printStackTrace(); return null; } HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = null; try { response = (HttpResponse) httpclient.execute(httpRequest); } catch (IOException e) { e.printStackTrace(); return null; } HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = null; try { bufHttpEntity = new BufferedHttpEntity(entity); final int bufferSize = 1024 * 50; BufferedInputStream imageBis = new BufferedInputStream(bufHttpEntity.getContent(), bufferSize); long contentLength = bufHttpEntity.getContentLength(); Bitmap decodedBitmap = decode(imageBis); try { imageBis.close(); } catch (IOException e1) { } encode(decodedBitmap, cachedImageFile.toURL(), CompressFormat.PNG, mImageCacheQuality); Calendar cal = Calendar.getInstance(); long currentTime = cal.getTime().getTime(); if (mUseCacheDatabase) { mCacheRecordDbHelper.insertCacheRecord(mDb, cachedImageFile.toURL(), currentTime, contentLength); } if (decodedBitmap != null) { mBitmapMap.put(url, decodedBitmap); } return decodedBitmap; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java
public Drawable GetGraph(String urlString) throws IOException, URISyntaxException { HttpGet httpRequest = new HttpGet(new URL(ZENOSS_INSTANCE + urlString).toURI()); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); final long contentLength = bufHttpEntity.getContentLength(); //Log.e("GetGraph",Long.toString(contentLength)); if (contentLength >= 0) { InputStream is = bufHttpEntity.getContent(); Bitmap bitmap = BitmapFactory.decodeStream(is); /*ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 10, out); // w w w .jav a 2s. c om return new BitmapDrawable(BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())));*/ is.close(); return new BitmapDrawable(bitmap); } else { return null; } }