List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.jivesoftware.sdk.utils.JiveSDKUtils.java
public static String decodeUrl(@Nonnull String url) { try {/*from w w w .j a va 2 s.co m*/ return URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException uee) { //TODO: LOGGER System.err.println("Failed decoding URL using UTF-8 charset" + uee.getMessage()); //noinspection deprecation return URLDecoder.decode(url); } }
From source file:ext.sns.util.AuthUtil.java
/** * ?state?/*from w ww . j a v a2 s . com*/ * * @param state ?state? * @return ?null */ public static Map<String, String> decodeState(String state) { if (StringUtils.isBlank(state)) { return null; } Map<String, String> params = null; try { String decode = URLDecoder.decode(state.replace('_', '%'), "utf-8"); String[] encodeParamArray = decode.split("&"); params = new HashMap<String, String>(); for (int i = 0; i < encodeParamArray.length; i = i + 2) { String key = URLDecoder.decode(encodeParamArray[i], "utf-8"); String val = URLDecoder.decode(encodeParamArray[i + 1], "utf-8"); params.put(key, val); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return params; }
From source file:com.switchfly.inputvalidation.canonicalizer.QueryStringCanonicalizer.java
@Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; }/*w w w. jav a2 s. c om*/ String s = super.execute(content); try { s = URLDecoder.decode(s, "UTF-8"); } catch (Exception e) { throw new RuntimeException(e); } return s; }
From source file:org.mobicents.servlet.sip.restcomm.util.HttpUtils.java
public static List<NameValuePair> toList(final String data) throws UnsupportedEncodingException { final List<NameValuePair> list = new ArrayList<NameValuePair>(); final String[] tokens = data.split("&"); for (final String token : tokens) { final String[] parts = token.split("="); if (parts.length == 1) { list.add(new BasicNameValuePair(parts[0], null)); } else if (parts.length == 2) { list.add(new BasicNameValuePair(parts[0], URLDecoder.decode(parts[1], "UTF-8"))); }/*from w w w . j a v a 2 s. c o m*/ } return list; }
From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java
public static void newActivityTemplateManager() throws IOException, InterruptedException { String[] cmd = null;/*from w w w . j av a 2 s .c o m*/ String templatePath = URLDecoder .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8"); templatePath = templatePath.replace("/", File.separator); templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib")); templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator; templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities" + File.separator; String[] env = null; if (!new File(templatePath + mobileServicesTemplateName).exists()) { String tmpdir = getTempLocation(); BufferedInputStream bufferedInputStream = new BufferedInputStream( ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip")); unZip(bufferedInputStream, tmpdir); if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { try { copyFolder(new File(tmpdir + mobileServicesTemplateName), new File(templatePath + mobileServicesTemplateName)); copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName)); } catch (IOException ex) { PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat"); printWriter.println("@echo off"); printWriter.println("md \"" + templatePath + mobileServicesTemplateName + "\""); printWriter.println("md \"" + templatePath + officeTemplateName + "\""); printWriter.println("xcopy \"" + tmpdir + mobileServicesTemplateName + "\" \"" + templatePath + mobileServicesTemplateName + "\" /s /i /Y"); printWriter.println("xcopy \"" + tmpdir + officeTemplateName + "\" \"" + templatePath + officeTemplateName + "\" /s /i /Y"); printWriter.flush(); printWriter.close(); String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" }; cmd = tmpcmd; ArrayList<String> tempenvlist = new ArrayList<String>(); for (String envval : System.getenv().keySet()) tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval))); tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1"); env = new String[tempenvlist.size()]; tempenvlist.toArray(env); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd, env, new File(tmpdir)); proc.waitFor(); //wait for elevate command to finish Thread.sleep(3000); if (!new File(templatePath + mobileServicesTemplateName).exists()) UIHelper.showException( "Error copying template files. Please refer to documentation to copy manually.", new Exception()); } } else { if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { String[] strings = { "osascript", // "-e", // "do shell script \"mkdir -p \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"", // "-e", // "do shell script \"mkdir -p \\\"/" + templatePath + officeTemplateName + "\\\"\"", "-e", "do shell script \"cp -Rp \\\"" + tmpdir + mobileServicesTemplateName + "\\\" \\\"/" + templatePath + "\\\"\"", "-e", "do shell script \"cp -Rp \\\"" + tmpdir + officeTemplateName + "\\\" \\\"/" + templatePath + "\\\"\"" }; exec(strings, tmpdir); } else { try { copyFolder(new File(tmpdir + mobileServicesTemplateName), new File(templatePath + mobileServicesTemplateName)); copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName)); } catch (IOException ex) { JPasswordField pf = new JPasswordField(); int okCxl = JOptionPane.showConfirmDialog(null, pf, "To copy Microsoft Services templates, the plugin needs your password:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { String password = new String(pf.getPassword()); exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp", tmpdir + mobileServicesTemplateName, templatePath + mobileServicesTemplateName }, tmpdir); exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp", tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir); } } } } } }
From source file:de.citec.sc.index.ProcessAnchorFile.java
public static void run(String filePath) { try {//from ww w . j a v a2s .c o m File file = new File("new.ttl"); // if file doesnt exists, then create it if (file.exists()) { file.delete(); file.createNewFile(); } if (!file.exists()) { file.createNewFile(); } BufferedReader wpkg = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8")); String line = ""; PrintStream ps = new PrintStream("new.ttl", "UTF-8"); while ((line = wpkg.readLine()) != null) { String[] data = line.split("\t"); if (data.length == 3) { String label = data[0]; label = StringEscapeUtils.unescapeJava(label); try { label = URLDecoder.decode(label, "UTF-8"); } catch (Exception e) { } String uri = data[1].replace("http://dbpedia.org/resource/", ""); uri = StringEscapeUtils.unescapeJava(uri); try { uri = URLDecoder.decode(uri, "UTF-8"); } catch (Exception e) { } String f = data[2]; label = label.toLowerCase(); ps.println(label + "\t" + uri + "\t" + f); } } wpkg.close(); ps.close(); File oldFile = new File(filePath); oldFile.delete(); oldFile.createNewFile(); file.renameTo(oldFile); } catch (Exception e) { e.printStackTrace(); } }
From source file:ru.apertum.qsystem.reports.net.NetUtil.java
public static synchronized String getEntityContent(HttpRequest request) { String result = map_ec.get(request); if (result == null) { if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); try { result = EntityUtils.toString(entity); } catch (IOException | ParseException ex) { throw new ReportException(ex.toString()); }//w w w . j a v a2 s . co m } else { result = ""; } try { result = URLDecoder.decode(result, "utf-8"); } catch (UnsupportedEncodingException ex) { throw new ReportException(ex.toString()); } map_ec.put(request, result); } return result; }
From source file:com.ms.commons.test.common.FileUtil.java
public static File convertURLToFile(URL url) { if (url == null) { return null; }/* w ww .j a v a2s .c o m*/ try { return new File(url.toURI()); } catch (URISyntaxException e) { try { return new File(URLDecoder.decode(url.getPath(), "UTF-8")); } catch (UnsupportedEncodingException e1) { return new File(url.getPath()); } } }
From source file:com.googlecode.batchfb.util.StringUtils.java
/** * Masks the useless checked exception from URLDecoder.decode() *//*from w w w . ja va2 s.c o m*/ public static String urlDecode(String string) { try { return URLDecoder.decode(string, "utf-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:org.zht.framework.web.controller.DownloadController.java
@RequestMapping(value = "/download") public String download(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "filename") String filename) throws Exception { filename = filename.replace("/", "\\"); if (StringUtils.isEmpty(filename) || filename.contains("\\.\\.")) { response.setContentType("text/html;charset=utf-8"); response.getWriter().write("??"); return null; }/*from w w w . j a v a2 s . co m*/ filename = URLDecoder.decode(filename, "UTF-8"); String projectPath = request.getServletContext().getRealPath("/"); String filePath = projectPath + File.separator + filename; DownloadUtils.download(request, response, filePath, filename); return null; }