List of usage examples for java.net URLEncoder encode
@Deprecated public static String encode(String s)
From source file:Main.java
@SuppressWarnings("deprecation") public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; }/*from w ww .j av a 2 s.c om*/ StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) first = false; else sb.append("&"); if (parameters.getString(key) != null) { sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key))); } } return sb.toString(); }
From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java
private static Bitmap downloadGravatar(final String id) throws IOException { final URL aURL = new URL("http://www.gravatar.com/avatar/" + URLEncoder.encode(id) + "?size=100&d=mm"); final HttpURLConnection conn = (HttpURLConnection) aURL.openConnection(); conn.setDoInput(true);// w ww . j a va2 s . co m conn.connect(); final InputStream is = conn.getInputStream(); final Bitmap bm = BitmapFactory.decodeStream(is); is.close(); return bm; }
From source file:Main.java
/** * Convert to String a date that is received as parameter. * * @param date the date// w w w.j ava 2s . co m * @return String */ public static String toStringDate(Date date) { String formatoFecha = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; SimpleDateFormat sdf = new SimpleDateFormat(formatoFecha); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return date == null ? null : URLEncoder.encode(sdf.format(date)); }
From source file:Main.java
public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; }//from w ww.ja v a 2s. com StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { Object parameter = parameters.get(key); if (!(parameter instanceof String)) { continue; } if (first) first = false; else sb.append("&"); sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key))); } return sb.toString(); }
From source file:Main.java
@Deprecated public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; }//from w ww.java 2 s.c o m StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { Object parameter = parameters.get(key); if (!(parameter instanceof String)) { continue; } if (first) first = false; else sb.append("&"); sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key))); } return sb.toString(); }
From source file:uk.bcu.services.MusicSearchService.java
public MusicSearchService(String query) { this.query = URLEncoder.encode(query); }
From source file:com.handlerexploit.news.data.WeatherProvider.java
public static WeatherInfo getWeather(String location) { WeatherInfo weatherInfo = null;/*from ww w. ja v a2s.c om*/ if (mFileManager != null) { weatherInfo = (WeatherInfo) mFileManager.get(location); if (weatherInfo != null) { return weatherInfo; } } String jsonResponse = YQLHelper.query( String.format(BASE_YQL_QUERY, String.format(WEATHER_URL_TEMPLATE, URLEncoder.encode(location)))); if (jsonResponse == null) { if (mFileManager != null) { weatherInfo = (WeatherInfo) mFileManager.get(location, true); if (weatherInfo != null) { return weatherInfo; } else { return null; } } else { return null; } } try { weatherInfo = new WeatherInfo( new JSONObject(jsonResponse).getJSONObject("xml_api_reply").getJSONObject("weather")); } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } if (mFileManager != null && weatherInfo != null) { mFileManager.put(location, weatherInfo); } return weatherInfo; }
From source file:uk.bcu.services.ItunesSearchService.java
public ItunesSearchService(String query) { this.query1 = URLEncoder.encode(query); }
From source file:com.shinylife.smalltools.api.ApiImpl.java
public AddressInfo getAddressInfo(String no) { try {/*from w ww .j av a2 s . c om*/ String response = HttpRequest(String.format(Constants.API_URL, "zip", URLEncoder.encode(no))); if (response != null && response.length() > 0) { AddressInfo ai = new AddressInfo(); JSONObject jb = new JSONObject(response); ai.setCity(jb.getString("city")); ai.setLocation(jb.getString("location")); ai.setPhone(jb.getString("phone")); ai.setZipcode(jb.getString("zipcode")); ai.setProvince(jb.getString("province")); return ai; } } catch (Exception e) { // TODO: handle exception } return null; }
From source file:kltn.geocoding.Geocoding.java
private static Geometry getBoundary(String s) throws MalformedURLException, IOException, org.json.simple.parser.ParseException { String link = "https://maps.googleapis.com/maps/api/geocode/json?&key=AIzaSyALCgmmer3Cht-mFQiaJC9yoWdSqvfdAiM"; link = link + "&address=" + URLEncoder.encode(s); URL url = new URL(link); HttpsURLConnection httpsCon = (HttpsURLConnection) url.openConnection(); InputStream is = httpsCon.getInputStream(); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); String jsonString = writer.toString(); JSONParser parse = new JSONParser(); Object obj = parse.parse(jsonString); JSONObject jsonObject = (JSONObject) obj; System.out.println(s);/*from ww w.j a v a 2 s. com*/ System.out.println(jsonObject.toJSONString()); JSONArray resultArr = (JSONArray) jsonObject.get("results"); Object resultObject = parse.parse(resultArr.get(0).toString()); JSONObject resultJsonObject = (JSONObject) resultObject; Object geoObject = parse.parse(resultJsonObject.get("geometry").toString()); JSONObject geoJsonObject = (JSONObject) geoObject; if (!geoJsonObject.containsKey("bounds")) { return null; } Object boundObject = parse.parse(geoJsonObject.get("bounds").toString()); JSONObject boundJsonObject = (JSONObject) boundObject; // System.out.println(boundJsonObject.toJSONString()); Object southwest = parse.parse(boundJsonObject.get("southwest").toString()); JSONObject southwestJson = (JSONObject) southwest; String southwestLat = southwestJson.get("lat").toString(); String southwestLong = southwestJson.get("lng").toString(); Object northeast = parse.parse(boundJsonObject.get("northeast").toString()); JSONObject northeastJson = (JSONObject) northeast; String northeastLat = northeastJson.get("lat").toString(); String northeastLong = northeastJson.get("lng").toString(); String polygon = "POLYGON((" + southwestLong.trim() + " " + northeastLat.trim() + "," + northeastLong.trim() + " " + northeastLat.trim() + "," + northeastLong.trim() + " " + southwestLat.trim() + "," + southwestLong.trim() + " " + southwestLat.trim() + "," + southwestLong.trim() + " " + northeastLat.trim() + "))"; Geometry geo = wktToGeometry(polygon); return geo; }