@Test public void getQueryParamsEmptyAndNormalValuesCombinedTest() throws MalformedURLException { URL url = new URL("http: Map<String, List<String>> params = Util.getQueryParams(url); assertThat(params.get("param1"), contains("value1")); assertThat(params.get("param2"), contains("")); assertTrue(params.containsKey("param3")); assertThat(params.get("param4"), contains("value4")); }
public static Map<String, List<String>> getQueryParams(final URL url) { if (url == null) { throw new IllegalArgumentException("Cannot get query params from the null url"); } Map<String, List<String>> returnValue = new HashMap<>(); if (url.getQuery() == null) { return returnValue; } String[] pairs = url.getQuery().split("&"); for (String pair : pairs) { if (pair.isEmpty()) { continue; } int idx = pair.indexOf('='); if (idx == -1) { returnValue.computeIfAbsent(pair, k -> new LinkedList<>()); continue; } String key = pair.substring(0, idx); String value = pair.substring(idx + 1); try { key = URLDecoder.decode(key, StandardCharsets.UTF_8.toString()); value = URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Could not find UTF-8 encoding", e); } List<String> paramValues = returnValue.computeIfAbsent(key, k -> new LinkedList<>()); paramValues.add(value); } return returnValue; }
Util { public static Map<String, List<String>> getQueryParams(final URL url) { if (url == null) { throw new IllegalArgumentException("Cannot get query params from the null url"); } Map<String, List<String>> returnValue = new HashMap<>(); if (url.getQuery() == null) { return returnValue; } String[] pairs = url.getQuery().split("&"); for (String pair : pairs) { if (pair.isEmpty()) { continue; } int idx = pair.indexOf('='); if (idx == -1) { returnValue.computeIfAbsent(pair, k -> new LinkedList<>()); continue; } String key = pair.substring(0, idx); String value = pair.substring(idx + 1); try { key = URLDecoder.decode(key, StandardCharsets.UTF_8.toString()); value = URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Could not find UTF-8 encoding", e); } List<String> paramValues = returnValue.computeIfAbsent(key, k -> new LinkedList<>()); paramValues.add(value); } return returnValue; } }
Util { public static Map<String, List<String>> getQueryParams(final URL url) { if (url == null) { throw new IllegalArgumentException("Cannot get query params from the null url"); } Map<String, List<String>> returnValue = new HashMap<>(); if (url.getQuery() == null) { return returnValue; } String[] pairs = url.getQuery().split("&"); for (String pair : pairs) { if (pair.isEmpty()) { continue; } int idx = pair.indexOf('='); if (idx == -1) { returnValue.computeIfAbsent(pair, k -> new LinkedList<>()); continue; } String key = pair.substring(0, idx); String value = pair.substring(idx + 1); try { key = URLDecoder.decode(key, StandardCharsets.UTF_8.toString()); value = URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Could not find UTF-8 encoding", e); } List<String> paramValues = returnValue.computeIfAbsent(key, k -> new LinkedList<>()); paramValues.add(value); } return returnValue; } private  Util(); }
Util { public static Map<String, List<String>> getQueryParams(final URL url) { if (url == null) { throw new IllegalArgumentException("Cannot get query params from the null url"); } Map<String, List<String>> returnValue = new HashMap<>(); if (url.getQuery() == null) { return returnValue; } String[] pairs = url.getQuery().split("&"); for (String pair : pairs) { if (pair.isEmpty()) { continue; } int idx = pair.indexOf('='); if (idx == -1) { returnValue.computeIfAbsent(pair, k -> new LinkedList<>()); continue; } String key = pair.substring(0, idx); String value = pair.substring(idx + 1); try { key = URLDecoder.decode(key, StandardCharsets.UTF_8.toString()); value = URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Could not find UTF-8 encoding", e); } List<String> paramValues = returnValue.computeIfAbsent(key, k -> new LinkedList<>()); paramValues.add(value); } return returnValue; } private  Util(); static String prehtmlize(String s); static String prehtmlize(CharSequence q); static void qurlencode(String str, Appendable dest); static String htmlize(String s); static String htmlize(CharSequence q); static void htmlize(CharSequence q, Appendable dest, boolean pre); static void htmlize(CharSequence q, Appendable dest); static void htmlize(char[] cs, int length, Appendable dest); static String breadcrumbPath(String urlPrefix, String path); static String breadcrumbPath(String urlPrefix, String path, char sep); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact, boolean isDir); static String getCanonicalPath(String path, char sep); static String getEmail(String author); static String readableSize(long num); static String readableCount(long count); static String encode(String s); static void encode(String s, Appendable dest); static String encodeURL(String urlStr); static void readableLine(int num, Writer out, Annotation annotation,
            String userPageLink, String userPageSuffix, String project); static void readableLine(int num, Writer out, Annotation annotation, String userPageLink,
            String userPageSuffix, String project, boolean skipNewline); static String path2uid(String path, String date); static String uid2url(String uid); static String fixPathIfWindows(String path); static void writeHAD(Writer out, String ctxE, String entry,
            boolean is_dir); static String URIEncode(String q); static void URIEncode(String str, Appendable dest); static void appendQuery(StringBuilder buf, String key,
            String value); static String URIEncodePath(String path); static String formQuoteEscape(String q); static String[] diffline(StringBuilder line1, StringBuilder line2); @SuppressWarnings("boxing") static void dumpConfiguration(Appendable out); static void dump(Writer out, Reader in); static boolean dump(Writer out, File dir, String filename,
            boolean compressed); static boolean dump(Writer out, File file, boolean compressed); static boolean dumpXref(Writer out, File file, boolean compressed,
            String contextPath); static void dumpXref(Writer out, Reader in, String contextPath); static String jsStringLiteral(String str); static String stripPathPrefix(String prefix, String fullPath); static String createSlider(int offset, int limit, int size); static String createSlider(int offset, int limit, long size, HttpServletRequest request); static boolean isHttpUri(String string); static String redactUrl(String path); static String linkify(String url); static String linkify(String url, boolean newTab); static String buildLink(String name, Map<String, String> attrs); static String buildLink(String name, String url); static String buildLink(String name, String url, boolean newTab); static String linkifyPattern(String text, Pattern pattern, String name, String url); static String completeUrl(String url, HttpServletRequest req); static Map<String, List<String>> getQueryParams(final URL url); }
Util { public static Map<String, List<String>> getQueryParams(final URL url) { if (url == null) { throw new IllegalArgumentException("Cannot get query params from the null url"); } Map<String, List<String>> returnValue = new HashMap<>(); if (url.getQuery() == null) { return returnValue; } String[] pairs = url.getQuery().split("&"); for (String pair : pairs) { if (pair.isEmpty()) { continue; } int idx = pair.indexOf('='); if (idx == -1) { returnValue.computeIfAbsent(pair, k -> new LinkedList<>()); continue; } String key = pair.substring(0, idx); String value = pair.substring(idx + 1); try { key = URLDecoder.decode(key, StandardCharsets.UTF_8.toString()); value = URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Could not find UTF-8 encoding", e); } List<String> paramValues = returnValue.computeIfAbsent(key, k -> new LinkedList<>()); paramValues.add(value); } return returnValue; } private  Util(); static String prehtmlize(String s); static String prehtmlize(CharSequence q); static void qurlencode(String str, Appendable dest); static String htmlize(String s); static String htmlize(CharSequence q); static void htmlize(CharSequence q, Appendable dest, boolean pre); static void htmlize(CharSequence q, Appendable dest); static void htmlize(char[] cs, int length, Appendable dest); static String breadcrumbPath(String urlPrefix, String path); static String breadcrumbPath(String urlPrefix, String path, char sep); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact, boolean isDir); static String getCanonicalPath(String path, char sep); static String getEmail(String author); static String readableSize(long num); static String readableCount(long count); static String encode(String s); static void encode(String s, Appendable dest); static String encodeURL(String urlStr); static void readableLine(int num, Writer out, Annotation annotation,
            String userPageLink, String userPageSuffix, String project); static void readableLine(int num, Writer out, Annotation annotation, String userPageLink,
            String userPageSuffix, String project, boolean skipNewline); static String path2uid(String path, String date); static String uid2url(String uid); static String fixPathIfWindows(String path); static void writeHAD(Writer out, String ctxE, String entry,
            boolean is_dir); static String URIEncode(String q); static void URIEncode(String str, Appendable dest); static void appendQuery(StringBuilder buf, String key,
            String value); static String URIEncodePath(String path); static String formQuoteEscape(String q); static String[] diffline(StringBuilder line1, StringBuilder line2); @SuppressWarnings("boxing") static void dumpConfiguration(Appendable out); static void dump(Writer out, Reader in); static boolean dump(Writer out, File dir, String filename,
            boolean compressed); static boolean dump(Writer out, File file, boolean compressed); static boolean dumpXref(Writer out, File file, boolean compressed,
            String contextPath); static void dumpXref(Writer out, Reader in, String contextPath); static String jsStringLiteral(String str); static String stripPathPrefix(String prefix, String fullPath); static String createSlider(int offset, int limit, int size); static String createSlider(int offset, int limit, long size, HttpServletRequest request); static boolean isHttpUri(String string); static String redactUrl(String path); static String linkify(String url); static String linkify(String url, boolean newTab); static String buildLink(String name, Map<String, String> attrs); static String buildLink(String name, String url); static String buildLink(String name, String url, boolean newTab); static String linkifyPattern(String text, Pattern pattern, String name, String url); static String completeUrl(String url, HttpServletRequest req); static Map<String, List<String>> getQueryParams(final URL url);  }