List of usage examples for org.apache.http.entity BufferedHttpEntity getContent
public InputStream getContent() throws IOException
From source file:markson.visuals.sitapp.settingActivity.java
public static String getCancelNum() { String classNum = "0"; DefaultHttpClient client = new DefaultHttpClient(); try {// w ww . ja v a 2s .co m HttpGet httpGet = new HttpGet("http://marksonvisuals.com/sitapp/ccnum.php"); HttpResponse response = client.execute(httpGet); HttpEntity ht = response.getEntity(); BufferedHttpEntity buf = new BufferedHttpEntity(ht); InputStream is = buf.getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line; while ((line = r.readLine()) != null) { total.append(line + "\n"); } classNum = total.toString().replaceAll("[^0-9]", ""); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return classNum; }
From source file:utils.APIExporter.java
/** * This method get the API thumbnail and write in to the zip file * @param uuid API id of the API/* w ww . j av a2s . c o m*/ * @param accessToken valide access token with view scope * @param APIFolderpath archive base path */ private static void exportAPIThumbnail(String uuid, String accessToken, String APIFolderpath) { ApiImportExportConfiguration config = ApiImportExportConfiguration.getInstance(); try { //REST API call to get API thumbnail String url = config.getPublisherUrl() + "apis/" + uuid + "/thumbnail"; CloseableHttpClient client = HttpClientGenerator.getHttpClient(config.getCheckSSLCertificate()); HttpGet request = new HttpGet(url); request.setHeader(HttpHeaders.AUTHORIZATION, ImportExportConstants.CONSUMER_KEY_SEGMENT + " " + accessToken); CloseableHttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); //assigning the response in to inputStream BufferedHttpEntity httpEntity = new BufferedHttpEntity(entity); InputStream imageStream = httpEntity.getContent(); byte[] byteArray = IOUtils.toByteArray(imageStream); InputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(byteArray)); //getting the mime type of the input Stream String mimeType = URLConnection.guessContentTypeFromStream(inputStream); //getting file extension String extension = getThumbnailFileType(mimeType); OutputStream outputStream = null; if (extension != null) { //writing image in to the archive try { outputStream = new FileOutputStream(APIFolderpath + File.separator + "icon." + extension); IOUtils.copy(httpEntity.getContent(), outputStream); } finally { IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(imageStream); IOUtils.closeQuietly(inputStream); } } } catch (IOException e) { log.error("Error occurred while exporting the API thumbnail"); } }
From source file:com.kku.apps.pricesearch.util.HttpConnection.java
public static Bitmap getBitmapFromUrl(String url) { HttpGet method = new HttpGet(url); DefaultHttpClient httpClient = new DefaultHttpClient(); try {//from w w w . j av a 2 s . c om BufferedHttpEntity entity = httpClient.execute(method, new ResponseHandler<BufferedHttpEntity>() { @Override public BufferedHttpEntity handleResponse(HttpResponse response) throws ClientProtocolException, IOException { // Xe?[^XR?[h int status = response.getStatusLine().getStatusCode(); if (HttpStatus.SC_OK != status) { throw new RuntimeException("?MG?[?"); } HttpEntity entity = response.getEntity(); BufferedHttpEntity bufferEntity = new BufferedHttpEntity(entity); return bufferEntity; } }); InputStream is = entity.getContent(); return BitmapFactory.decodeStream(is); } catch (ClientProtocolException e) { throw new RuntimeException(e); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } finally { httpClient.getConnectionManager().shutdown(); } }
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.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.universalimageloader1.core.download.HttpClientImageDownloader.java
@Override protected InputStream getStreamFromNetwork(URI imageUri, Object extra) { try {//from w w w. ja v a 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.example.android.navigationdrawerexample.LocationFileReader.java
public List<String[]> getFile() throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(url); HttpResponse response = httpclient.execute(httppost); HttpEntity ht = response.getEntity(); BufferedHttpEntity buf = new BufferedHttpEntity(ht); InputStream is = buf.getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line;/* w ww . j av a2s .co m*/ String[] location; while ((line = r.readLine()) != null) { total.append(line + "\n"); location = total.toString().split(" "); locationList.add(location); total.setLength(0); } return locationList; }
From source file:ca.marcmeszaros.papyrus.remote.DownloadThumbnails.java
@Override protected LinkedList<Bitmap> doInBackground(URL... urls) { // some class variables HttpGet httpRequest;//from w ww.j av a 2 s .c o m Bitmap bm; LinkedList<Bitmap> bitmaps = new LinkedList<Bitmap>(); try { // loop through all urls for (URL url : urls) { // create the HTTP request httpRequest = new HttpGet(url.toURI()); // create an HTTP client and get the response HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); // get a handle on the http entity HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); // read the entity from the stream into a bitmap object bm = BitmapFactory.decodeStream(instream); // add the bitmap to the list bitmaps.add(bm); } } catch (URISyntaxException e) { Log.e(TAG, "URISyntaxException", e); } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException", e); } catch (IOException e) { Log.e(TAG, "IOException", e); } return bitmaps; }
From source file:libraryjava.parseJSON.java
/** * method Bitmap deprecated/* w w w . ja v a 2s . co m*/ * @param urll * @return */ public Bitmap doInBackgroundDeprecated(String urll) { StrictMode(); try { URL url = new URL(urll); HttpGet httpRequest = new HttpGet(url.toURI()); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity); InputStream input = bufferedEntity.getContent(); return BitmapFactory.decodeStream(input); } catch (Exception ex) { return null; } }
From source file:com.dngames.mobilewebcam.PhotoSettings.java
public static void GETSettings(final Context context) { // check for new settings when done final SharedPreferences prefs = context.getSharedPreferences(MobileWebCam.SHARED_PREFS_NAME, 0); final String settingsurl = prefs.getString("remote_config_url", ""); final int settingsfreq = Math.max(1, PhotoSettings.getEditInt(context, prefs, "remote_config_every", 1)); final String login = prefs.getString("remote_config_login", ""); final String password = prefs.getString("remote_config_password", ""); final boolean noToasts = prefs.getBoolean("no_messages", false); if (settingsurl.length() > 0 && gLastGETSettingsPictureCnt < MobileWebCam.gPictureCounter && (MobileWebCam.gPictureCounter % settingsfreq) == 0) { gLastGETSettingsPictureCnt = MobileWebCam.gPictureCounter; Handler h = new Handler(context.getMainLooper()); h.post(new Runnable() { @Override/*from w w w .j a va 2s . c o m*/ public void run() { new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { try { DefaultHttpClient httpclient = new DefaultHttpClient(); if (login.length() > 0) { try { ((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials( new AuthScope(null, -1), new UsernamePasswordCredentials(login, password)); } catch (Exception e) { e.printStackTrace(); if (e.getMessage() != null) MobileWebCam.LogE("http login " + e.getMessage()); else MobileWebCam.LogE("http: unable to log in"); return null; } } HttpGet get = new HttpGet(settingsurl); HttpResponse response = httpclient.execute(get); HttpEntity ht = response.getEntity(); BufferedHttpEntity buf = new BufferedHttpEntity(ht); InputStream is = buf.getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line; while ((line = r.readLine()) != null) total.append(line + "\n"); if (ht.getContentType().getValue().startsWith("text/plain")) return total.toString(); else return "GET Config Error!\n" + total.toString(); } catch (Exception e) { e.printStackTrace(); if (e.getMessage() != null) { MobileWebCam.LogE(e.getMessage()); return "GET Config Error!\n" + e.getMessage(); } } return null; } @Override protected void onPostExecute(String result) { if (result != null) { if (result.startsWith("GET Config Error!\n")) { if (!noToasts) Toast.makeText(context, result, Toast.LENGTH_SHORT).show(); } else { PhotoSettings.GETSettings(context, result, prefs); } } else if (!noToasts) Toast.makeText(context, "GET config failed!", Toast.LENGTH_SHORT).show(); } }.execute(); } }); } }