mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-01 22:14:01 +03:00
[ANY] Add query helper
This commit is contained in:
parent
b719255bd5
commit
f4d0783d94
2 changed files with 37 additions and 0 deletions
|
@ -258,6 +258,14 @@ public static ArgsParseResult parseJavaArgs(List<String> args) {
|
|||
return new ArgsParseResult(conf, classpath, jvmArgs, mainClass, mainModule, jarFile, args);
|
||||
}
|
||||
|
||||
public static <K, V> V multimapFirstOrNullValue(K key, Map<K, List<V>> params) {
|
||||
List<V> list = params.getOrDefault(key, Collections.emptyList());
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
public record ArgsParseResult(LaunchOptions.ModuleConf conf, List<String> classpath, List<String> jvmArgs, String mainClass, String mainModule, String jarFile, List<String> args) {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package pro.gravit.utils.helper;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
public class QueryHelper {
|
||||
public static Map<String, List<String>> splitUriQuery(URI uri) {
|
||||
var query = uri.getRawQuery();
|
||||
if (query == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, List<String>> params = new HashMap<>();
|
||||
String[] split = query.split("&");
|
||||
for (String qParams : split) {
|
||||
String[] splitParams = qParams.split("=");
|
||||
List<String> strings = params.computeIfAbsent(URLDecoder.decode(splitParams[0], StandardCharsets.UTF_8),
|
||||
k -> new ArrayList<>(1));
|
||||
strings.add(URLDecoder.decode(splitParams[1], StandardCharsets.UTF_8));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public static String encodeFormPair(String key, String value) {
|
||||
return URLEncoder.encode(key, StandardCharsets.UTF_8) + "=" + URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue