All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hibegin.http.server.util.HttpQueryStringUtils Maven / Gradle / Ivy

Go to download

Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project. Can quickly run embedded, Android devices

There is a newer version: 0.3.162
Show newest version
package com.hibegin.http.server.util;

import java.util.*;

public class HttpQueryStringUtils {

    public static Map parseUrlEncodedStrToMap(String queryString) {
        if (Objects.isNull(queryString) || queryString.isEmpty()) {
            return new HashMap<>();
        }
        Map> tempParam = new HashMap<>();
        String[] args = queryString.split("&");
        for (String string : args) {
            int idx = string.indexOf("=");
            if (idx != -1) {
                String key = string.substring(0, idx);
                String value = string.substring(idx + 1);
                if (tempParam.containsKey(key)) {
                    tempParam.get(key).add(value);
                } else {
                    List paramValues = new ArrayList<>();
                    paramValues.add(value);
                    tempParam.put(key, paramValues);
                }
            }
        }
        Map paramMap = new HashMap<>();
        for (Map.Entry> entry : tempParam.entrySet()) {
            paramMap.put(entry.getKey(), entry.getValue().toArray(new String[0]));
        }
        return paramMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy