Top Description Fields Constructors Methods
io.netty5.handler.codec.http

public Class QueryStringEncoder

extends Object
Class Inheritance
Imports
io.netty5.util.internal.StringUtil, java.net.URI, .URISyntaxException, .URLEncoder, java.nio.charset.Charset

Creates a URL-encoded URI from a path string and key-value parameter pairs. This encoder is for one time use only. Create a new instance for each URI.
QueryStringEncoder encoder = new QueryStringEncoder("/hello");
encoder.addParam("recipient", "world");
assert encoder.toString().equals("/hello?recipient=world");
See Also
QueryStringDecoder

Field Summary

Modifier and TypeField and Description
private static final char[]
private final Charset
private boolean
private final StringBuilder
private static final byte

Constructor Summary

AccessConstructor and Description
public
QueryStringEncoder(String uri)

Creates a new encoder that encodes a URI that starts with the specified path string.

public
QueryStringEncoder(String uri, Charset charset)

Creates a new encoder that encodes a URI that starts with the specified path string in the specified charset.

Method Summary

Modifier and TypeMethod and Description
public void
addParam(String name, String value)

Adds a parameter with the specified name and value to this encoder.

private void
private static boolean

Returns:

true or false
dontNeedEncoding
(char
the char to be judged whether it need to be encoded
ch
)

Determines whether the given character is an unreserved character.

private void
private void
encodeNonUtf8Component(CharSequence
The String to encode
s
)

Encode the String as per RFC 3986, Section 2.

private void
private void
encodeUtf8Component(CharSequence s, int encodingStart, int len)

private void
encodeUtf8ComponentSlow(CharSequence s, int start, int len)

private static char

Returns:

the char representation of the specified digit in hexadecimal.
forDigit
(int
the number to convert to a character.
digit
)

Convert the given digit to an upper hexadecimal char.

public String
toString()

Overrides java.lang.Object.toString.

Returns the URL-encoded URI which was created from the path string specified in the constructor and the parameters added by addParam(String, String) method.
public URI
toUri()

Returns the URL-encoded URI object which was created from the path string specified in the constructor and the parameters added by addParam(String, String) method.

private void
writeUtf8Surrogate(char c, char c2)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CHAR_MAPback to summary
private static final char[] CHAR_MAP
charsetback to summary
private final Charset charset
hasParamsback to summary
private boolean hasParams
uriBuilderback to summary
private final StringBuilder uriBuilder
WRITE_UTF_UNKNOWNback to summary
private static final byte WRITE_UTF_UNKNOWN

Constructor Detail

QueryStringEncoderback to summary
public QueryStringEncoder(String uri)

Creates a new encoder that encodes a URI that starts with the specified path string. The encoder will encode the URI in UTF-8.

QueryStringEncoderback to summary
public QueryStringEncoder(String uri, Charset charset)

Creates a new encoder that encodes a URI that starts with the specified path string in the specified charset.

Method Detail

addParamback to summary
public void addParam(String name, String value)

Adds a parameter with the specified name and value to this encoder.

appendEncodedback to summary
private void appendEncoded(int b)
dontNeedEncodingback to summary
private static boolean dontNeedEncoding(char ch)

Determines whether the given character is an unreserved character.

unreserved characters do not need to be encoded, and include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde.

unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" / "*"

Parameters
ch:char

the char to be judged whether it need to be encoded

Returns:boolean

true or false

encodeComponentback to summary
private void encodeComponent(CharSequence s)
encodeNonUtf8Componentback to summary
private void encodeNonUtf8Component(CharSequence s)

Encode the String as per RFC 3986, Section 2.

There is a little different between the JDK's encode method : URLEncoder#encode(String, String). The JDK's encoder encode the space to + and this method directly encode the blank to %20 beyond that, this method reuse the uriBuilder in this class rather than create a new one, thus generates less garbage for the GC.

Parameters
s:CharSequence

The String to encode

encodeUtf8Componentback to summary
private void encodeUtf8Component(CharSequence s)
encodeUtf8Componentback to summary
private void encodeUtf8Component(CharSequence s, int encodingStart, int len)
encodeUtf8ComponentSlowback to summary
private void encodeUtf8ComponentSlow(CharSequence s, int start, int len)
forDigitback to summary
private static char forDigit(int digit)

Convert the given digit to an upper hexadecimal char.

Parameters
digit:int

the number to convert to a character.

Returns:char

the char representation of the specified digit in hexadecimal.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the URL-encoded URI which was created from the path string specified in the constructor and the parameters added by addParam(String, String) method.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
toUriback to summary
public URI toUri() throws URISyntaxException

Returns the URL-encoded URI object which was created from the path string specified in the constructor and the parameters added by addParam(String, String) method.

writeUtf8Surrogateback to summary
private void writeUtf8Surrogate(char c, char c2)