# Class CharEscapers (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.CharEscapers)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.util.escape.CharEscapers)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.escape.CharEscapers)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.escape.CharEscapers)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.escape.CharEscapers)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.escape.CharEscapers)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.escape.CharEscapers)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.escape.CharEscapers)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.escape.CharEscapers)

    public final class CharEscapers

Utility functions for encoding and decoding URIs.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> CharEscapers

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### decodeUri(String uri)

    public static String decodeUri(String uri)

Decodes application/x-www-form-urlencoded strings. The UTF-8 character set determines what
characters are represented by any consecutive sequences of the form "%*XX*".

This replaces each occurrence of '+' with a space, ' '. This method should not be used for
non-application/x-www-form-urlencoded strings such as host and path.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `uri` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` a percent-encoded US-ASCII string |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | a string without any percent escapes or plus signs |

### decodeUriPath(String path)

    public static String decodeUriPath(String path)

Decodes the path component of a URI. This does not convert + into spaces (the behavior of
java.net.URLDecoder#decode(String, String)). This method transforms URI encoded values
into their decoded symbols.

e.g. `decodePath("%3Co%3E")` returns `"`

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the value to be decoded |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | decoded version of `path` |

### escapeUri(String value)

    public static String escapeUri(String value)

Escapes the string value so it can be safely included in application/x-www-form-urlencoded
data. This is not appropriate for generic URI escaping. In particular it encodes the space
character as a plus sign instead of percent escaping it, in contravention of the URI
specification. For details on application/x-www-form-urlencoded encoding see the see [HTML 4 specification,
section 17.13.4.1](https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1).

When encoding a String, the following rules apply:

- The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
- The special characters ".", "-", "\*", and "_" remain the same.
- The space character " " is converted into a plus sign "+".
- All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then represented by the 3-character string "%XY", where "XY" is the two-digit, uppercase, hexadecimal representation of the byte value.

**Note** : Unlike other escapers, URI escapers produce uppercase hexadecimal sequences.
From [RFC 3986](http://tools.ietf.org/html/rfc3986):  

*"URI producers and normalizers should use uppercase hexadecimal digits for all percent-encodings."*

This escaper has identical behavior to (but is potentially much faster than):

- java.net.URLEncoder#encode(String, String) with the encoding name "UTF-8"

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### escapeUriConformant(String value)

    public static String escapeUriConformant(String value)

Escapes the string value so it can be safely included in any part of a URI. For details on
escaping URIs, see [RFC 3986 - section
2.4](http://tools.ietf.org/html/rfc3986#section-2.4).

When encoding a String, the following rules apply:

- The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
- The special characters ".", "-", "\*", and "_" remain the same.
- The space character " " is converted into "%20".
- All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then represented by the 3-character string "%XY", where "XY" is the two-digit, uppercase, hexadecimal representation of the byte value.

**Note** : Unlike other escapers, URI escapers produce uppercase hexadecimal sequences.
From [RFC 3986](http://tools.ietf.org/html/rfc3986):  

*"URI producers and normalizers should use uppercase hexadecimal digits for all percent-encodings."*

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### escapeUriPath(String value)

    public static String escapeUriPath(String value)

Escapes the string value so it can be safely included in URI path segments. For details on
escaping URIs, see [RFC 3986 - section
2.4](http://tools.ietf.org/html/rfc3986#section-2.4).

When encoding a String, the following rules apply:

- The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
- The unreserved characters ".", "-", "\~", and "_" remain the same.
- The general delimiters "@" and ":" remain the same.
- The subdelimiters "!", "$", "\&", "'", "(", ")", "\*", ",", ";", and "=" remain the same.
- The space character " " is converted into %20.
- All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then represented by the 3-character string "%XY", where "XY" is the two-digit, uppercase, hexadecimal representation of the byte value.

**Note** : Unlike other escapers, URI escapers produce uppercase hexadecimal sequences.
From [RFC 3986](http://tools.ietf.org/html/rfc3986):  

*"URI producers and normalizers should use uppercase hexadecimal digits for all percent-encodings."*

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### escapeUriPathWithoutReserved(String value)

    public static String escapeUriPathWithoutReserved(String value)

Escapes a URI path but retains all reserved characters, including all general delimiters. That
is the same as [#escapeUriPath(String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.CharEscapers#com_google_api_client_util_escape_CharEscapers_escapeUriPath_java_lang_String_) except that it does not escape '?', '+', and '/'.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### escapeUriPathWithoutReservedAndPercentEncoded(String value)

    public static String escapeUriPathWithoutReservedAndPercentEncoded(String value)

Escapes a URI path but retains all reserved and percent-encoded characters. That is the same as
[#escapeUriPathWithoutReserved(String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.escape.CharEscapers#com_google_api_client_util_escape_CharEscapers_escapeUriPathWithoutReserved_java_lang_String_) except that it also escapes percent encoded
parts.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### escapeUriQuery(String value)

    public static String escapeUriQuery(String value)

Escapes the string value so it can be safely included in URI query string segments. When the
query string consists of a sequence of name=value pairs separated by \&, the names and
values should be individually encoded. If you escape an entire query string in one pass with
this escaper, then the "=" and "\&" characters used as separators will also be escaped.

This escaper is also suitable for escaping fragment identifiers.

For details on escaping URIs, see [RFC 3986 - section 2.4](http://tools.ietf.org/html/rfc3986#section-2.4).

When encoding a String, the following rules apply:

- The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
- The unreserved characters ".", "-", "\~", and "_" remain the same.
- The general delimiters "@" and ":" remain the same.
- The path delimiters "/" and "?" remain the same.
- The subdelimiters "!", "$", "'", "(", ")", "\*", ",", and ";", remain the same.
- The space character " " is converted into %20.
- The equals sign "=" is converted into %3D.
- The ampersand "\&" is converted into %26.
- All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then represented by the 3-character string "%XY", where "XY" is the two-digit, uppercase, hexadecimal representation of the byte value.

**Note** : Unlike other escapers, URI escapers produce uppercase hexadecimal sequences.
From [RFC 3986](http://tools.ietf.org/html/rfc3986):  

*"URI producers and normalizers should use uppercase hexadecimal digits for all percent-encodings."*

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### escapeUriUserInfo(String value)

    public static String escapeUriUserInfo(String value)

Escapes the string value so it can be safely included in URI user info part. For details on
escaping URIs, see [RFC 3986 - section
2.4](http://tools.ietf.org/html/rfc3986#section-2.4).

When encoding a String, the following rules apply:

- The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
- The unreserved characters ".", "-", "\~", and "_" remain the same.
- The general delimiter ":" remains the same.
- The subdelimiters "!", "$", "\&", "'", "(", ")", "\*", ",", ";", and "=" remain the same.
- The space character " " is converted into %20.
- All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then represented by the 3-character string "%XY", where "XY" is the two-digit, uppercase, hexadecimal representation of the byte value.

**Note** : Unlike other escapers, URI escapers produce uppercase hexadecimal sequences.
From [RFC 3986](http://tools.ietf.org/html/rfc3986):  

*"URI producers and normalizers should use uppercase hexadecimal digits for all percent-encodings."*

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |