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:coral.utils.CoralUtils.java

/**
 * convert string into parameter map//from   w  w w .  j a v  a2s  .c o m
 * 
 * @param arg
 * @return
 */
public static Map<String, String> urlToMap(String arg) {
    Map<String, String> args = new HashMap<String, String>();
    int startOfQuery = arg.indexOf('?') + 1;
    for (String part : arg.substring(startOfQuery, arg.length()).split("&")) {
        String[] var = part.split("=");
        if (var[0] != null) {
            try {
                args.put(var[0], (var.length > 1) ? URLDecoder.decode(var[1], "UTF-8").trim() : "");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(
                        "Just rethrow as a RuntimeException, something went wrong here (i.e. no support for UTF-8, which is universal).",
                        e);
            }
        }
    }
    return args;
}

From source file:de.rub.nds.burp.utilities.Encoding.java

/**
 * Check for URL encoding./*from  ww  w  .  jav  a 2s.  c o m*/
 * @param data The encoded data.
 * @return True if the encoding is URL Encoding, otherwise false.
 */
public static boolean isURLEncoded(String data) {
    boolean flag = true;
    //filter non ASCII chars
    if (!regex_contains("([^\\x00-\\x7F])", data)) {
        try {
            String tmp = URLDecoder.decode(data, "ASCII");
            if (tmp.equals(data)) {
                return false;
            }
        } catch (UnsupportedEncodingException ex) {
            flag = false;
        }
    } else {
        flag = false;
    }
    String pattern = "(%[a-zA-Z0-9]{2})";
    return (flag && regex_contains(pattern, data));
}

From source file:mixi4j.internal.util.z_M4JInternalParseUtil.java

public static String getURLDecodedString(String name, JSONObject json) {
    String returnValue = getRawString(name, json);
    if (returnValue != null) {
        try {//from   w  w w . j a  v a2s.c  o m
            returnValue = URLDecoder.decode(returnValue, "UTF-8");
        } catch (UnsupportedEncodingException ignore) {
        }
    }
    return returnValue;
}

From source file:net.dv8tion.discord.Yui.java

public static File getThisJarFile() throws UnsupportedEncodingException {
    //Gets the path of the currently running Jar file
    String path = Yui.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String decodedPath = URLDecoder.decode(path, "UTF-8");

    //This is code especially written for running and testing this program in an IDE that doesn't compile to .jar when running.
    if (!decodedPath.endsWith(".jar")) {
        return new File("Yui.jar");
    }/*from  w ww .  j  a  va  2 s. c om*/
    return new File(decodedPath); //We use File so that when we send the path to the ProcessBuilder, we will be using the proper System path formatting.
}

From source file:org.neo4j.ext.udc.impl.PingerHandler.java

@Override
public void handle(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext)
        throws HttpException, IOException {
    final String requestUri = httpRequest.getRequestLine().getUri();
    final int offset = requestUri.indexOf("?");
    if (offset > -1) {
        String query = requestUri.substring(offset + 1);
        String[] params = query.split("\\+");
        if (params.length > 0) {
            for (String param : params) {
                String[] pair = param.split("=");
                String key = URLDecoder.decode(pair[0], "UTF-8");
                String value = URLDecoder.decode(pair[1], "UTF-8");
                queryMap.put(key, value);
            }/* ww  w. j  a  v a  2 s.  c  o m*/
        }
    }
}

From source file:com.lll.util.EncodeUtils.java

/**
 * URL ?./*from w w  w .  ja  v a  2  s  .co  m*/
 */
public static String urlDecode(String input, String encoding) {
    try {
        return URLDecoder.decode(input, encoding);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported Encoding Exception", e);
    }
}

From source file:org.jorge.lolin1.io.net.HTTPServices.java

public static void downloadFile(final String whatToDownload, final File whereToSaveIt) throws IOException {
    logString("debug", "Downloading url " + whatToDownload);
    AsyncTask<Void, Void, Object> imageDownloadAsyncTask = new AsyncTask<Void, Void, Object>() {
        @Override//from   w  ww . jav a  2 s  .co m
        protected Object doInBackground(Void... params) {
            Object ret = null;
            BufferedInputStream bufferedInputStream = null;
            FileOutputStream fileOutputStream = null;
            try {
                logString("debug", "Opening stream for " + whatToDownload);
                bufferedInputStream = new BufferedInputStream(
                        new URL(URLDecoder.decode(whatToDownload, "UTF-8").replaceAll(" ", "%20"))
                                .openStream());
                logString("debug", "Opened stream for " + whatToDownload);
                fileOutputStream = new FileOutputStream(whereToSaveIt);

                final byte data[] = new byte[1024];
                int count;
                logString("debug", "Loop-writing " + whatToDownload);
                while ((count = bufferedInputStream.read(data, 0, 1024)) != -1) {
                    fileOutputStream.write(data, 0, count);
                }
                logString("debug", "Loop-written " + whatToDownload);
            } catch (IOException e) {
                return e;
            } finally {
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (IOException e) {
                        ret = e;
                    }
                }
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e) {
                        ret = e;
                    }
                }
            }
            return ret;
        }
    };
    imageDownloadAsyncTask.executeOnExecutor(fileDownloadExecutor);
    Object returned = null;
    try {
        returned = imageDownloadAsyncTask.get();
    } catch (ExecutionException | InterruptedException e) {
        Crashlytics.logException(e);
    }
    if (returned != null) {
        throw (IOException) returned;
    }
}

From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java

/**
 * make argument to map/*from w w  w .j a  v  a2  s .  c  o  m*/
 * @param strArgument
 * @return
 * @throws UnsupportedEncodingException
 */
public static Map<String, String> maekArgumentTOMap(String strArgument)
        throws RESTFULUnsupportedEncodingException {
    if (StringUtils.split(strArgument, "&") == null)
        return new HashMap<String, String>();

    if (logger.isDebugEnabled())
        logger.debug("original URL is ===> " + strArgument);
    Map<String, String> params = new HashMap<String, String>();

    try {
        for (String param : StringUtils.split(strArgument, "&")) {
            String pair[] = StringUtils.split(param, "=");
            String key = URLDecoder.decode(pair[0], "UTF-8");

            String value = "";
            if (pair.length > 1) {
                try {
                    value = URLDecoder.decode(pair[1], "UTF-8");
                } catch (Exception e) {
                    value = pair[1];
                }
            }

            params.put(key, value);
        }
    } catch (UnsupportedEncodingException e1) {
        throw new RESTFULUnsupportedEncodingException(e1);
    }

    return params;
}

From source file:io.kamax.mxisd.controller.profile.v1.ProfileInternalController.java

@RequestMapping(method = GET, path = "/_matrix-internal/profile/v1/{userId:.+}")
public String getProfile(@PathVariable String userId) throws UnsupportedEncodingException {
    userId = URLDecoder.decode(userId, StandardCharsets.UTF_8.name());
    _MatrixID mxId = MatrixID.asAcceptable(userId);

    return GsonUtil.get().toJson(GsonUtil.makeObj("roles", GsonUtil.asArray(mgr.getRoles(mxId))));
}

From source file:net.fenyo.mail4hotspot.web.GMailOAuthStep1Servlet.java

private String urlDecode(final String url) throws UnsupportedEncodingException {
    return URLDecoder.decode(url, "UTF-8");
}