An object that converts literal text into a format safe for inclusion in a particular context
(such as an XML document). Typically (but not always), the inverse process of "unescaping" the
text is performed automatically by the relevant parser.
For example, an XML escaper would convert the literal string "Foo<Bar>" into
"Foo<Bar>" to prevent "<Bar>" from being confused with an XML tag. When the
resulting XML document is parsed, the parser API will return this text as the original literal
string "Foo<Bar>".
An Escaper instance is required to be stateless, and safe when used concurrently by
multiple threads.
Several popular escapers are defined as constants in the class CharEscapers.
A UnicodeEscaper that escapes some set of Java characters using the URI percent encoding
scheme. The set of safe characters (those which remain unescaped) is specified on construction.
When encoding a String, the following rules apply:
The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the
same.
Any additionally specified safe characters remain the same.
If plusForSpace is true, the space character " " is converted into a plus sign "+".
All other characters are converted into one or more bytes using UTF-8 encoding. Each byte
is then represented by the 3-character string "%XY", where "XY" is the two-digit,
uppercase, hexadecimal representation of the byte value.
RFC 3986 defines the set of unreserved characters as "-", "_", "~", and "." It goes on to
state:
URIs that differ in the replacement of an unreserved character with its corresponding
percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI
comparison implementations do not always perform normalization prior to comparison (see Section
6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT
(%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by
URI producers and, when found in a URI, should be decoded to their corresponding unreserved
characters by URI normalizers.
Note: This escaper produces uppercase hexadecimal sequences. From RFC 3986: "URI producers and normalizers should use uppercase hexadecimal digits for all
percent-encodings."
An Escaper that converts literal text into a format safe for inclusion in a particular
context (such as an XML document). Typically (but not always), the inverse process of
"unescaping" the text is performed automatically by the relevant parser.
For example, an XML escaper would convert the literal string "Foo<Bar>" into
"Foo<Bar>" to prevent "<Bar>" from being confused with an XML tag. When the
resulting XML document is parsed, the parser API will return this text as the original literal
string "Foo<Bar>".
As there are important reasons, including potential security issues, to handle Unicode
correctly if you are considering implementing a new escaper you should favor using UnicodeEscaper
wherever possible.
A UnicodeEscaper instance is required to be stateless, and safe when used concurrently
by multiple threads.
Several popular escapers are defined as constants in the class CharEscapers. To create
your own escapers extend this class and implement the #escape(int) method.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Package com.google.api.client.util.escape (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.escape)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.escape)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.escape)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.escape)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.escape)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.escape)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.escape) \nCharacter escaping utilities.\n\nClasses\n-------\n\n### [CharEscapers](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.CharEscapers)\n\nUtility functions for encoding and decoding URIs.\n\n### [Escaper](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.Escaper)\n\nAn object that converts literal text into a format safe for inclusion in a particular context\n(such as an XML document). Typically (but not always), the inverse process of \"unescaping\" the\ntext is performed automatically by the relevant parser.\n\nFor example, an XML escaper would convert the literal string `\"Foo\u003cBar\u003e\"` into `\n\"Foo\u003cBar\u003e\"` to prevent `\"\u003cBar\u003e\"` from being confused with an XML tag. When the\nresulting XML document is parsed, the parser API will return this text as the original literal\nstring `\"Foo\u003cBar\u003e\"`.\n\nAn `Escaper` instance is required to be stateless, and safe when used concurrently by\nmultiple threads.\n\nSeveral popular escapers are defined as constants in the class [CharEscapers](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.CharEscapers).\n\n### [PercentEscaper](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.PercentEscaper)\n\nA `UnicodeEscaper` that escapes some set of Java characters using the URI percent encoding\nscheme. The set of safe characters (those which remain unescaped) is specified on construction.\n\nFor details on escaping URIs for use in web pages, see [RFC 3986 - section 2.4](http://tools.ietf.org/html/rfc3986#section-2.4) and [RFC 3986 - appendix A](http://tools.ietf.org/html/rfc3986#appendix-A)\n\nWhen encoding a String, the following rules apply:\n\n- The alphanumeric characters \"a\" through \"z\", \"A\" through \"Z\" and \"0\" through \"9\" remain the same.\n- Any additionally specified safe characters remain the same.\n- If `plusForSpace` is true, the space character \" \" is converted into a plus sign \"+\".\n- All other characters are converted into one or more bytes using UTF-8 encoding. Each byte is then represented by the 3-character string \"%XY\", where \"XY\" is the two-digit, uppercase, hexadecimal representation of the byte value.\n\nRFC 3986 defines the set of unreserved characters as \"-\", \"_\", \"\\~\", and \".\" It goes on to\nstate:\n\nURIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers.\n\n**Note** : This escaper produces uppercase hexadecimal sequences. From [RFC 3986](https://tools.ietf.org/html/rfc3986): \n\n*\"URI producers and normalizers should use uppercase hexadecimal digits for all\npercent-encodings.\"*\n\n### [UnicodeEscaper](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.UnicodeEscaper)\n\nAn [Escaper](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.Escaper) that converts literal text into a format safe for inclusion in a particular\ncontext (such as an XML document). Typically (but not always), the inverse process of\n\"unescaping\" the text is performed automatically by the relevant parser.\n\nFor example, an XML escaper would convert the literal string `\"Foo\u003cBar\u003e\"` into `\n\"Foo\u003cBar\u003e\"` to prevent `\"\u003cBar\u003e\"` from being confused with an XML tag. When the\nresulting XML document is parsed, the parser API will return this text as the original literal\nstring `\"Foo\u003cBar\u003e\"`.\n\nAs there are important reasons, including potential security issues, to handle Unicode\ncorrectly if you are considering implementing a new escaper you should favor using UnicodeEscaper\nwherever possible.\n\nA `UnicodeEscaper` instance is required to be stateless, and safe when used concurrently\nby multiple threads.\n\nSeveral popular escapers are defined as constants in the class [CharEscapers](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.CharEscapers). To create\nyour own escapers extend this class and implement the [#escape(int)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.UnicodeEscaper#com_google_api_client_util_escape_UnicodeEscaper_escape_int_) method."]]