private void changeServer(HttpPost httpPost, String sufix) { String ip = RoundRobin.getInstance() .getAnotherIP( this.fragment.getActivity().getApplicationContext(), httpPost.getURI().getHost()); httpPost.setURI(URI.create(ip + sufix)); }
private HttpPost createHttpPost() { HttpPost httpPost = new HttpPost( RoundRobin.getInstance().getIP(this.fragment.getActivity().getApplicationContext()) + Global.API_JSON_ADDRESS); httpPost.addHeader( ApplicationContentDownloaderAsyncTask.HTTP_POST_HEADER_ACCEPT_KEY, ApplicationContentDownloaderAsyncTask.HTTP_POST_HEADER_ACCEPT_VALUE); httpPost.addHeader( ApplicationContentDownloaderAsyncTask.HTTP_POST_HEADER_CONTENT_TYPE_KEY, ApplicationContentDownloaderAsyncTask.HTTP_POST_HEADER_CONTENT_TYPE_VALUE); return httpPost; }
private void saveImageInDatabase(XmlPullParser xmlParser) { String url = xmlParser.getAttributeValue( null, ApplicationContentDownloaderAsyncTask.IMAGE_SOURCE_TAG_NAME); Bitmap bitmap; try { bitmap = BitmapFactory.decodeStream( new URL( RoundRobin.getInstance() .getIP(this.fragment.getActivity().getApplicationContext()) + "/" + url) .openStream()); } catch (MalformedURLException e1) { e1.printStackTrace(); Log.e(Global.TAG, "image source error"); return; } catch (IOException e1) { e1.printStackTrace(); Log.e(Global.TAG, "image source error"); return; } String[] urlParts = url.split("/"); FileOutputStream fileStream; try { fileStream = this.fragment .getActivity() .getApplicationContext() .openFileOutput(urlParts[urlParts.length - 1], Context.MODE_PRIVATE); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileStream); fileStream.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); Log.e(Global.TAG, "image saving in filesystem error"); return; } catch (IOException e) { e.printStackTrace(); Log.e(Global.TAG, "image saving in filesystem error"); return; } try { while (xmlParser.getEventType() != XmlPullParser.END_TAG) { xmlParser.next(); } } catch (XmlPullParserException e) { e.printStackTrace(); Log.e(Global.TAG, "xml error"); } catch (IOException e) { e.printStackTrace(); Log.e(Global.TAG, "xml error"); } }