List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:logic.core.file.FileSystemInit.java
public static void init() { try {//w ww .jav a2s. c om jarPathOnSystem = FilenameUtils.getPath(URLDecoder.decode( GameRunner.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8")); String dataPath = jarPathOnSystem + "/data/"; File temp = new File(dataPath); temp.mkdir(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:Main.java
private static String urlDecode(String str) { try {//from ww w . j av a 2s . c o m return URLDecoder.decode(str, UTF8); } catch (UnsupportedEncodingException ex) { return str; } }
From source file:Main.java
/** * Returns the folder that contains a jar that contains the class * * @param aclass a class to find a jar//from w ww .j a v a 2s . co m * @return */ public static String getJarContainingFolderPath(Class aclass) throws Exception { CodeSource codeSource = aclass.getProtectionDomain().getCodeSource(); File jarFile; if (codeSource.getLocation() != null) { jarFile = new File(codeSource.getLocation().toURI()); } else { String path = aclass.getResource(aclass.getSimpleName() + ".class").getPath(); int startIndex = path.indexOf(":") + 1; int endIndex = path.indexOf("!"); if (startIndex == -1 || endIndex == -1) { throw new IllegalStateException( "Class " + aclass.getSimpleName() + " is located not within a jar: " + path); } String jarFilePath = path.substring(startIndex, endIndex); jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8"); jarFile = new File(jarFilePath); } return jarFile.getParentFile().getAbsolutePath(); }
From source file:com.github.breadmoirai.samurai.util.SearchResult.java
public static SearchResult fromGoogle(JSONObject googleResult) { SearchResult result = new SearchResult(); result.title = cleanString(googleResult.getString("title")); result.content = cleanString(googleResult.getString("snippet")); try {//from w w w . ja va2 s . co m result.url = URLDecoder.decode(cleanString(googleResult.getString("link")), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; }
From source file:io.wcm.caravan.io.http.impl.CaravanHttpHelper.java
/** * @param token Token to decode// w ww. ja va 2s . co m * @return Decoded token */ public static String urlDecode(final String token) { try { return URLDecoder.decode(token, Charsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.skubit.bitid.JwtBuilder.java
public static String buildRequest(ECKey mKey, TidBit tidbit) throws UnsupportedEncodingException, NoSuchAlgorithmException, JSONException, InvalidKeyException { JSONObject claims = new JSONObject(); long iat = (System.currentTimeMillis() / 1000L); String address = URLDecoder.decode(mKey.toAddress(MainNetParams.get()).toString(), "UTF-8"); claims.put("iss", address); claims.put("iat", iat); claims.put("jti", tidbit.getNonce()); claims.put("exp", iat + 180L); claims.put("aud", tidbit.getRawUri()); claims.put("scope", tidbit.getScope()); claims.put("app", tidbit.getApplication()); return signAndBuildWebToken(claims, mKey); }
From source file:org.openscore.content.httpclient.build.Utils.java
public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode) throws UrlEncodeException { List<BasicNameValuePair> list = new ArrayList<>(); String[] pairs = params.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("=", 2); String name = nameValue[0]; String value = nameValue.length == 2 ? nameValue[1] : null; if (!urlEncode) { try { name = URLDecoder.decode(name, "UTF-8"); if (value != null) { value = URLDecoder.decode(value, "UTF-8"); }//from w w w . ja v a2 s. c o m } catch (UnsupportedEncodingException e) { //never happens throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } list.add(new BasicNameValuePair(name, value)); } return list; }
From source file:UrlUtils.java
/** * Decodes using URLDecoder - use when queries or form post values are decoded * @param value value to decode/*w ww . jav a2s. com*/ * @return */ public static String urlDecode(String value) { try { value = URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { System.out.println("UTF-8 encoding can not be used to decode " + value); } return value; }
From source file:Main.java
/** * Parse a querystring into a map of key/value pairs. * * @param queryString the string to parse (without the '?') * @return key/value pairs mapping to the items in the querystring */// w ww . j a va 2s . c o m public static Map<String, String> parseQuerystring(String queryString) { Map<String, String> map = new HashMap<String, String>(); if ((queryString == null) || (queryString.equals(""))) { return map; } String[] params = queryString.split("&"); for (String param : params) { try { String[] keyValuePair = param.split("=", 2); String name = URLDecoder.decode(keyValuePair[0], "UTF-8"); if (name == "") { continue; } String value = keyValuePair.length > 1 ? URLDecoder.decode(keyValuePair[1], "UTF-8") : ""; map.put(name, value); } catch (UnsupportedEncodingException e) { // ignore this parameter if it can't be decoded } } return map; }
From source file:com.gc.iotools.fmt.base.TestUtils.java
public static String[] listFilesExcludingExtension(final String[] forbidden) throws IOException { final URL fileURL = TestUtils.class.getResource("/testFiles"); String filePath = URLDecoder.decode(fileURL.getPath(), "UTF-8"); final File dir = new File(filePath); final String[] files = dir.list(); final Collection<String> goodFiles = new Vector<String>(); if (!filePath.endsWith(File.separator)) { filePath = filePath + File.separator; }/*from w w w . j a va 2 s. c o m*/ for (final String file : files) { boolean insert = true; for (final String extForbidden : forbidden) { insert &= !(file.endsWith(extForbidden)); } if (insert) { goodFiles.add(filePath + file); } } return goodFiles.toArray(new String[goodFiles.size()]); }