com.king.platform.net.http.util.UriQueryParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of king-http-client Show documentation
Show all versions of king-http-client Show documentation
A asyncronous http client built ontop of netty.
// Copyright (C) king.com Ltd 2017
// https://github.com/king/king-http-client
// Author: Magnus Gustafsson
// License: Apache 2.0, https://raw.github.com/king/king-http-client/LICENSE-APACHE
package com.king.platform.net.http.util;
import io.netty.handler.codec.http.QueryStringDecoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class UriQueryParser {
private final QueryStringDecoder queryStringDecoder;
private final Map> parameters;
public UriQueryParser(String url) {
queryStringDecoder = new QueryStringDecoder(url);
parameters = queryStringDecoder.parameters();
}
public UriQueryParser(String url, Charset charset) {
queryStringDecoder = new QueryStringDecoder(url, charset);
parameters = queryStringDecoder.parameters();
}
public List getValue(String key) {
return parameters.get(key);
}
public String getValueOrDefault(String key, String defValue) {
List strings = parameters.get(key);
if (strings == null || strings.isEmpty()) {
return defValue;
}
return strings.get(0);
}
public boolean hasKey(String key) {
return parameters.containsKey(key);
}
public List params() {
List params = new ArrayList<>();
for (Map.Entry> entry : parameters.entrySet()) {
for (String value : entry.getValue()) {
params.add(new Param(entry.getKey(), value));
}
}
return params;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy