List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:Main.java
/** * Unmask the URI and return it// w w w .ja v a 2 s.c o m */ public static Uri unmaskLink(Uri uri, int i) { String s = null; List pathSegments; if (MASK_HOSTS_SEG[i] == null) { // The host always masks, no need to determine if it's the right segment s = uri.getQueryParameter(MASK_HOSTS_PAR[i]); } else { // Only a certain segment is used to mask URLs. Determine if this is it. pathSegments = uri.getPathSegments(); if (pathSegments == null) return uri; // If it is, unmask the URL. if (pathSegments.size() > 0 && MASK_HOSTS_SEG[i].equals(pathSegments.get(0))) s = uri.getQueryParameter(MASK_HOSTS_PAR[i]); } if (s == null) return uri; // Resolve link if it's relative try { if (!new URI(s).isAbsolute()) s = new URI(uri.toString()).resolve(s).toString(); } catch (URISyntaxException e) { e.printStackTrace(); } try { return Uri.parse(URLDecoder.decode(s, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return uri; } }
From source file:Main.java
@Deprecated public static Bundle decodeUrl(String s) { Bundle params = new Bundle(); if (s != null) { String array[] = s.split("&"); for (String parameter : array) { String v[] = parameter.split("="); try { if (v.length == 2) { params.putString(URLDecoder.decode(v[0], UTF8), URLDecoder.decode(v[1], UTF8)); } else if (v.length == 1) { params.putString(URLDecoder.decode(v[0], UTF8), ""); }//from w w w .j a va 2 s .c om } catch (UnsupportedEncodingException e) { // shouldn't happen } } } return params; }
From source file:com.nunofacha.chestmaster.commands.ChestHashCommand.java
public static String getPluginHash() { try {//from ww w. j a v a 2 s . c om String path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String decodedPath = URLDecoder.decode(path, "UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); String digest = getDigest(new FileInputStream(decodedPath), md, 2048); return digest; } catch (NoSuchAlgorithmException ex) { Logger.getLogger(ChestHashCommand.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(ChestHashCommand.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ChestHashCommand.class.getName()).log(Level.SEVERE, null, ex); } return "Failed to get MD5!"; }
From source file:com.aliyun.odps.ship.common.Util.java
private static String getRootDir() { String path = Util.class.getProtectionDomain().getCodeSource().getLocation().getPath(); if (path.endsWith(".jar")) { try {/*from w w w. ja va 2 s. c om*/ return URLDecoder.decode(path.substring(0, path.lastIndexOf("/")) + "/..", "UTF-8"); } catch (UnsupportedEncodingException e) { } } return new File(ODPSConsoleUtils.getConfigFilePath()).getParent() + "/file"; }
From source file:com.openshift.internal.util.URIUtils.java
public static Map<String, String> splitQuery(String q) { HashMap<String, String> params = new HashMap<String, String>(); if (q != null) { try {/*from ww w. j a va2s . c om*/ String decoded = URLDecoder.decode(q, StandardCharsets.UTF_8.toString()); String[] split = decoded.split("&"); for (String pair : split) { String[] keyValue = pair.split("="); if (keyValue.length >= 2) { params.put(keyValue[0], keyValue[1]); } } } catch (UnsupportedEncodingException e) { LOG.error("Unable to decode " + q, e); } } return params; }
From source file:com.hurence.logisland.utils.HttpUtils.java
/** * Take a url query string and split it into a map of key/values map * * @param urlQuery//from w w w .j a va 2 s . com * @return */ public static List<String> getQueryKeys(String urlQuery) { try { List<String> keys = new ArrayList<>(); if (urlQuery == null) { return keys; } for (String param : urlQuery.split("&")) { QueryParam queryParam = new QueryParam(); String[] pair = param.split("="); String key = URLDecoder.decode(pair[0], "UTF-8"); if (key != null && !key.equals("null")) { keys.add(key); } } return keys; } catch (UnsupportedEncodingException ex) { throw new AssertionError(ex); } }
From source file:com.fastbootmobile.encore.api.gimages.GoogleImagesClient.java
public static String getImageUrl(String query) throws IOException, JSONException, RateLimitException { if (query == null) { Log.e(TAG, "Null query!"); return null; }/*from w w w. ja v a2s . c om*/ String queryUrl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + URLEncoder.encode(query, "UTF-8") + "&imgsz=large"; JSONObject obj = JsonGet.getObject(queryUrl, "", true); JSONArray results = obj.getJSONObject("responseData").getJSONArray("results"); if (results.length() > 0) { return URLDecoder.decode(results.getJSONObject(0).getString("url"), "UTF-8"); } else { return null; } }
From source file:com.floragunn.searchguard.test.helper.file.FileHelper.java
public static File getAbsoluteFilePathFromClassPath(final String fileNameFromClasspath) { File file = null;/*from w ww .jav a 2 s .com*/ final URL fileUrl = AbstractSGUnitTest.class.getClassLoader().getResource(fileNameFromClasspath); if (fileUrl != null) { try { file = new File(URLDecoder.decode(fileUrl.getFile(), "UTF-8")); } catch (final UnsupportedEncodingException e) { return null; } if (file.exists() && file.canRead()) { return file; } else { log.error("Cannot read from {}, maybe the file does not exists? ", file.getAbsolutePath()); } } else { log.error("Failed to load " + fileNameFromClasspath); } return null; }
From source file:com.wavemaker.commons.util.WMUtils.java
public static String decodeRequestURI(String requestURI) { try {/*from w ww . ja va2 s. c o m*/ return URLDecoder.decode(requestURI, CommonConstants.UTF8); } catch (UnsupportedEncodingException e) { throw new WMRuntimeException("Failed to decode request URI", e); } }
From source file:jfix.util.Urls.java
/** * Decodes given application/x-www-form-urlencoded string using a specific * encoding scheme.//from w w w .j a va 2 s .co m */ public static String decode(String str, String enc) { try { return URLDecoder.decode(str, enc); } catch (Exception e) { return str; } }