Package libcore.net
Class UriCodec
java.lang.Object
libcore.net.UriCodec
public abstract class UriCodec extends Object
Encodes and decodes
application/x-www-form-urlencoded content.
Subclasses define exactly which characters are legal.
By default, UTF-8 is used to encode escaped characters. A single input character like "" may be encoded to multiple octets like %C2%80.
-
Constructor Summary
Constructors Constructor Description UriCodec() -
Method Summary
Modifier and Type Method Description voidappendEncoded(StringBuilder builder, String s)voidappendPartiallyEncoded(StringBuilder builder, String s)static Stringdecode(String s)static Stringdecode(String s, boolean convertPlus, Charset charset, boolean throwOnFailure)Stringencode(String s, Charset charset)protected abstract booleanisRetained(char c)Returns true ifcdoes not need to be escaped.Stringvalidate(String uri, int start, int end, String name)Throws ifsis invalid according to this encoder.static voidvalidateSimple(String s, String legal)Throws ifscontains characters that are not letters, digits or inlegal.
-
Constructor Details
-
UriCodec
public UriCodec()
-
-
Method Details
-
isRetained
protected abstract boolean isRetained(char c)Returns true ifcdoes not need to be escaped. -
validate
public final String validate(String uri, int start, int end, String name) throws URISyntaxExceptionThrows ifsis invalid according to this encoder.- Throws:
URISyntaxException
-
validateSimple
Throws ifscontains characters that are not letters, digits or inlegal.- Throws:
URISyntaxException
-
encode
-
appendEncoded
-
appendPartiallyEncoded
-
decode
public static String decode(String s, boolean convertPlus, Charset charset, boolean throwOnFailure)- Parameters:
convertPlus- true to convert '+' to ' '.throwOnFailure- true to throw an IllegalArgumentException on invalid escape sequences; false to replace them with the replacement character (U+fffd).
-
decode
-