QueryStringEncoder Class — netty Architecture
Architecture documentation for the QueryStringEncoder class in QueryStringEncoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 88739b5e_ab87_c690_d57f_c07e4748985e["QueryStringEncoder"] a2fd5e31_af1d_3fd1_801e_4686d9908244["QueryStringEncoder.java"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|defined in| a2fd5e31_af1d_3fd1_801e_4686d9908244 7313d9af_5152_2dee_ddcb_362feace032a["QueryStringEncoder()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 7313d9af_5152_2dee_ddcb_362feace032a 148e0c12_1f31_c076_f4a9_f02eebba9546["addParam()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 148e0c12_1f31_c076_f4a9_f02eebba9546 41cb5a12_6a49_bef0_0abe_33d43d26e61f["encodeComponent()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 41cb5a12_6a49_bef0_0abe_33d43d26e61f b951f773_f9af_9e3c_719b_681db65f555a["URI()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| b951f773_f9af_9e3c_719b_681db65f555a 85b3b5ca_5b74_d9c7_4429_2f9b66865420["String()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 85b3b5ca_5b74_d9c7_4429_2f9b66865420 ca1ef345_010a_8eda_186f_df0edd89c2f0["encodeNonUtf8Component()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| ca1ef345_010a_8eda_186f_df0edd89c2f0 79616a0a_4b03_da10_392b_24c9aae16249["encodeUtf8Component()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 79616a0a_4b03_da10_392b_24c9aae16249 6e537793_b2eb_9896_6f4e_18ef6539826b["encodeUtf8ComponentSlow()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 6e537793_b2eb_9896_6f4e_18ef6539826b 292af774_f477_a78b_4c13_7c754780ae80["writeUtf8Surrogate()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 292af774_f477_a78b_4c13_7c754780ae80 1e251d8b_1f4e_c93f_e50b_1d388bdd79dd["appendEncoded()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 1e251d8b_1f4e_c93f_e50b_1d388bdd79dd 8ec03c43_6983_aca0_fd58_47d9489609ca["forDigit()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 8ec03c43_6983_aca0_fd58_47d9489609ca 96c7280e_7a89_a791_3054_165b310c2092["dontNeedEncoding()"] 88739b5e_ab87_c690_d57f_c07e4748985e -->|method| 96c7280e_7a89_a791_3054_165b310c2092
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java lines 40–250
public class QueryStringEncoder {
private final Charset charset;
private final StringBuilder uriBuilder;
private boolean hasParams;
private static final byte WRITE_UTF_UNKNOWN = (byte) '?';
private static final char[] CHAR_MAP = "0123456789ABCDEF".toCharArray();
/**
* Creates a new encoder that encodes a URI that starts with the specified
* path string. The encoder will encode the URI in UTF-8.
*/
public QueryStringEncoder(String uri) {
this(uri, HttpConstants.DEFAULT_CHARSET);
}
/**
* Creates a new encoder that encodes a URI that starts with the specified
* path string in the specified charset.
*/
public QueryStringEncoder(String uri, Charset charset) {
ObjectUtil.checkNotNull(charset, "charset");
uriBuilder = new StringBuilder(uri);
this.charset = CharsetUtil.UTF_8.equals(charset) ? null : charset;
}
/**
* Adds a parameter with the specified name and value to this encoder.
*/
public void addParam(String name, String value) {
ObjectUtil.checkNotNull(name, "name");
if (hasParams) {
uriBuilder.append('&');
} else {
uriBuilder.append('?');
hasParams = true;
}
encodeComponent(name);
if (value != null) {
uriBuilder.append('=');
encodeComponent(value);
}
}
private void encodeComponent(CharSequence s) {
if (charset == null) {
encodeUtf8Component(s);
} else {
encodeNonUtf8Component(s);
}
}
/**
* Returns the URL-encoded URI object which was created from the path string
* specified in the constructor and the parameters added by
* {@link #addParam(String, String)} method.
*/
public URI toUri() throws URISyntaxException {
return new URI(toString());
}
/**
* Returns the URL-encoded URI which was created from the path string
* specified in the constructor and the parameters added by
* {@link #addParam(String, String)} method.
*/
@Override
public String toString() {
return uriBuilder.toString();
}
/**
* Encode the String as per RFC 3986, Section 2.
* <p>
* There is a little different between the JDK's encode method : {@link URLEncoder#encode(String, String)}.
* The JDK's encoder encode the space to {@code +} and this method directly encode the blank to {@code %20}
* beyond that , this method reuse the {@link #uriBuilder} in this class rather then create a new one,
* thus generates less garbage for the GC.
*
* @param s The String to encode
Source
Frequently Asked Questions
What is the QueryStringEncoder class?
QueryStringEncoder is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java.
Where is QueryStringEncoder defined?
QueryStringEncoder is defined in codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java at line 40.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free