Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:io.github.azige.moebooruviewer.io.MoebooruRepository.java

public File getOriginFile(Post post) {
    try {//from w  ww .  jav  a 2s  . c o m
        return new File(originDir, URLDecoder.decode(post.getOriginUrl().replaceFirst(".*/", ""), "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        LOG.error("URL?", ex);
        return null;
    }
}

From source file:eu.trentorise.game.api.rest.ConsoleController.java

@RequestMapping(method = RequestMethod.GET, value = "/game/{gameId}", produces = { "application/json" })
public GameDTO readGame(@PathVariable String gameId) {

    try {/* www .ja  v  a2s.c o  m*/
        gameId = URLDecoder.decode(gameId, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("gameId is not UTF-8 encoded");
    }

    Game g = gameSrv.loadGameDefinitionById(gameId);
    return g == null ? null : converter.convertGame(g);
}

From source file:com.floreantpos.license.FiveStarPOSLicenseManager.java

/**
 * Returns the license or throw a {@link LicenseException} if something is
 * wrong.//w w  w. ja  va2s .c o  m
 * 
 * @return {@link License}
 * @throws LicenseException
 */
public final License getLicense() throws LicenseException {

    try {

        File jarFile = new File(URLDecoder
                .decode(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"));
        String jarDirectory = (jarFile.getAbsolutePath().endsWith(".jar") ? jarFile.getParent()
                : jarFile.getParentFile().getParent());
        String licenseFilePath = String.format("%s%s%s", jarDirectory, File.separator, LICENSE_FILE);
        File licenseFile = new File(licenseFilePath);
        if (!licenseFile.exists()) {
            throw new LicenseException("License file not found! " + licenseFile.getAbsolutePath());
        }
        return loadLicense(licenseFile);

    } catch (LicenseException e) {
        throw e;
    } catch (Exception e) {
        throw new LicenseException("License file not found!", e);
    }
}

From source file:org.mule.module.http.functional.listener.HttpListenerUrlEncodedTestCase.java

@Test
public void invalidUrlEncodedParamsReturnInvalidRequestStatusCode() throws Exception {
    final Response response = Request.Post(getListenerUrl())
            .body(new StringEntity("Invalid url encoded content"))
            .addHeader(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED).execute();

    final HttpResponse httpResponse = response.returnResponse();

    assertThat(httpResponse.getStatusLine().getStatusCode(), equalTo(200));

    assertThat(/*from   ww w .j ava  2 s.c o m*/
            URLDecoder.decode(IOUtils.toString(httpResponse.getEntity().getContent()), Charsets.UTF_8.name()),
            is("Invalid url encoded content"));
}

From source file:com.networknt.utility.Util.java

public static String urlDecode(String value) {
    if (value == null || value.length() == 0) {
        return "";
    }//from w ww.  j av a 2  s  . c  o  m
    try {
        return URLDecoder.decode(value, Constants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.frostwire.search.bitsnoop.BitSnoopSearchResult.java

private String parseFileName(String urlEncodedFileName, String fallbackName) {
    String decodedFileName = fallbackName;
    try {// ww w  . j ava  2 s .c  o  m
        if (!StringUtils.isNullOrEmpty(urlEncodedFileName)) {
            decodedFileName = URLDecoder.decode(urlEncodedFileName, "UTF-8");
        }
    } catch (UnsupportedEncodingException e) {
    }
    return decodedFileName + ".torrent";
}

From source file:ke.alphacba.cms.core.util.RequestUtils.java

public static String getJSONString(HttpServletRequest request) {
    String CHARSET = "UTF-8";
    String json = "";
    try {/*  w  ww .ja v  a2 s. c  o m*/
        ServletInputStream in = request.getInputStream();
        String content = IOUtils.toString(in, CHARSET);
        json = URLDecoder.decode(content, CHARSET);
        json = json.substring(json.indexOf("=") + 1);
    } catch (IOException e) {

    }
    return json;
}

From source file:com.chiorichan.terminal.commands.UpdateCommand.java

@Override
public boolean execute(AccountAttachment sender, String command, String[] args) {
    if (!AutoUpdater.instance().isEnabled()) {
        sender.sendMessage(EnumColor.RED + "I'm sorry but updates are disabled per configs!");
        return true;
    }// w  w  w  .ja  v a2s  .com

    if (AppConfig.get().getBoolean("auto-updater.console-only") && !(sender instanceof AccountAttachment)) {
        sender.sendMessage(EnumColor.RED + "I'm sorry but updates can only be performed from the console!");
        return true;
    }

    if (!testPermission(sender))
        return true;

    if (args.length > 0)
        if (args[0].equalsIgnoreCase("latest"))
            try {
                if (args.length > 1 && args[1].equalsIgnoreCase("force")) {
                    BuildArtifact latest = AutoUpdater.instance().getLatest();

                    if (latest == null)
                        sender.sendMessage(EnumColor.RED
                                + "Please review the latest version without \"force\" arg before updating.");
                    else {
                        sender.sendMessage(EnumColor.YELLOW
                                + "Please wait as we download the latest version of Chiori Web Server...");

                        // TODO Add support for class files

                        File currentJar = new File(URLDecoder.decode(
                                Loader.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
                                "UTF-8"));
                        File updatedJar = new File("update.jar");

                        Download download = new Download(new URL(latest.getJar()), updatedJar.getName(),
                                updatedJar.getPath());
                        download.setListener(new DownloadProgressDisplay(sender));
                        download.run();

                        String origMD5 = new String(NetworkFunc.readUrl(latest.getMD5File())).trim();

                        if (origMD5 != null && !origMD5.isEmpty()) {
                            String descMD5 = DigestUtils.md5Hex(new FileInputStream(updatedJar.getPath()))
                                    .trim();

                            if (descMD5.equals(origMD5))
                                sender.sendMessage(EnumColor.AQUA
                                        + "SUCCESS: The downloaded jar and control MD5Checksum matched, '"
                                        + origMD5 + "'");
                            else {
                                sender.sendMessage(EnumColor.RED
                                        + "ERROR: The server said the downloaded jar should have a MD5Checksum of '"
                                        + origMD5 + "' but it had the MD5Checksum '" + descMD5
                                        + "', UPDATE ABORTED!!!");
                                FileUtils.deleteQuietly(updatedJar);
                                return true;
                            }
                        }

                        currentJar.delete();
                        FileInputStream fis = null;
                        FileOutputStream fos = null;
                        try {
                            fis = new FileInputStream(updatedJar);
                            fos = new FileOutputStream(currentJar);
                            IOUtils.copy(fis, fos);
                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            IOUtils.closeQuietly(fis);
                            IOUtils.closeQuietly(fos);
                        }

                        updatedJar.setExecutable(true, true);

                        String newMD5 = DigestUtils.md5Hex(new FileInputStream(currentJar.getPath())).trim();

                        if (origMD5 != null && !origMD5.isEmpty() && newMD5.equals(origMD5)) {
                            sender.sendMessage(EnumColor.AQUA + "----- Chiori Auto Updater -----");
                            sender.sendMessage(EnumColor.AQUA
                                    + "SUCCESS: The downloaded jar was successfully installed in the place of your old one.");
                            sender.sendMessage(EnumColor.AQUA + "You will need to restart "
                                    + Versioning.getProduct() + " for the changes to take effect.");
                            sender.sendMessage(EnumColor.AQUA
                                    + "Please type 'stop' and press enter to make this happen, otherwise you may encounter unexpected problems!");
                            sender.sendMessage(EnumColor.AQUA + "----- ------------------- -----");
                        } else {
                            sender.sendMessage(EnumColor.YELLOW + "----- Chiori Auto Updater -----");
                            sender.sendMessage(EnumColor.RED
                                    + "SEVERE: There was a problem installing the downloaded jar in the place of your old one.");
                            sender.sendMessage(EnumColor.RED
                                    + "Sorry about that because most likely your current jar is now currupt");
                            sender.sendMessage(EnumColor.RED + "Try redownloading this version yourself from: "
                                    + latest.getJar());
                            sender.sendMessage(EnumColor.RED + "Details: " + latest.getHtmlUrl());
                            sender.sendMessage(EnumColor.YELLOW + "----- ------------------- -----");
                        }

                        // Disable updater until next boot.
                        AutoUpdater.instance().setEnabled(false);

                        AppController.restartApplication(
                                "The update was successfully downloaded, restarting to apply it.");
                    }
                } else {
                    sender.sendMessage(EnumColor.AQUA + "Please wait as we poll the Jenkins Build Server...");
                    AutoUpdater.instance().forceUpdate(sender);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        else
            args = new String[0];

    if (args.length == 0) {
        sender.sendMessage(EnumColor.AQUA + "Please wait as we check for updates...");
        AutoUpdater.instance().check(sender, false);
    }

    return true;
}