# Class TextFormat (3.19.4)

    public final class TextFormat

Provide text parsing and formatting support for proto2 instances. The implementation largely
follows google/protobuf/text_format.cc.

## Inheritance

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

## 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

### \<T\>parse(CharSequence input, ExtensionRegistry extensionRegistry, Class\<T\> protoClass)

    public static T <T>parse(CharSequence input, ExtensionRegistry extensionRegistry, Class<T> protoClass)

Parse a text-format message from `input`. Extensions will be recognized if they are
registered in `extensionRegistry`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html` |
| `extensionRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ExtensionRegistry` |
| `protoClass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<T>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | the parsed message, guaranteed initialized |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.ParseException` |   |

### \<T\>parse(CharSequence input, Class\<T\> protoClass)

    public static T <T>parse(CharSequence input, Class<T> protoClass)

Parse a text-format message from `input`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html` |
| `protoClass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<T>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | the parsed message, guaranteed initialized |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.ParseException` |   |

### escapeBytes(byte\[\] input)

    public static String escapeBytes(byte[] input)

Like [#escapeBytes(ByteString)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat#com_google_protobuf_TextFormat_escapeBytes_com_google_protobuf_ByteString_), but used for byte array.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |

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

### escapeBytes(ByteString input)

    public static String escapeBytes(ByteString input)

Escapes bytes in the format used in protocol buffer text format, which is the same as the
format used for C string literals. All bytes that are not printable 7-bit ASCII characters are
escaped, as well as backslash, single-quote, and double-quote characters. Characters for which
no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` |

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

### escapeDoubleQuotesAndBackslashes(String input)

    public static String escapeDoubleQuotesAndBackslashes(String input)

Escape double quotes and backslashes in a String for emittingUnicode output of a message.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `input` | `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` |   |

### getParser()

    public static TextFormat.Parser getParser()

Return a [Parser](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Parser) instance which can parse text-format messages. The returned instance is
thread-safe.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.Parser` |   |

### merge(CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder)

    public static void merge(CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder)

Parse a text-format message from `input` and merge the contents into `builder`.
Extensions will be recognized if they are registered in `extensionRegistry`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html` |
| `extensionRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ExtensionRegistry` |
| `builder` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message.Builder` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.ParseException` |   |

### merge(CharSequence input, Message.Builder builder)

    public static void merge(CharSequence input, Message.Builder builder)

Parse a text-format message from `input` and merge the contents into `builder`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html` |
| `builder` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message.Builder` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.ParseException` |   |

### merge(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder)

    public static void merge(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder)

Parse a text-format message from `input` and merge the contents into `builder`.
Extensions will be recognized if they are registered in `extensionRegistry`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Readable.html` |
| `extensionRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ExtensionRegistry` |
| `builder` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message.Builder` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### merge(Readable input, Message.Builder builder)

    public static void merge(Readable input, Message.Builder builder)

Parse a text-format message from `input` and merge the contents into `builder`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Readable.html` |
| `builder` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message.Builder` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### print(MessageOrBuilder message, Appendable output) (deprecated)

    public static void print(MessageOrBuilder message, Appendable output)

**Deprecated.** *Use `printer().print(MessageOrBuilder, Appendable)`*

Outputs a textual representation of the Protocol Message supplied into the parameter output.
(This representation is the new version of the classic "ProtocolPrinter" output from the
original Protocol Buffer system)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### print(UnknownFieldSet fields, Appendable output) (deprecated)

    public static void print(UnknownFieldSet fields, Appendable output)

**Deprecated.** *Use `printer().print(UnknownFieldSet, Appendable)`*

Outputs a textual representation of `fields` to `output`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet` |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### printField(Descriptors.FieldDescriptor field, Object value, Appendable output) (deprecated)

    public static void printField(Descriptors.FieldDescriptor field, Object value, Appendable output)

**Deprecated.** *Use `printer().printField(FieldDescriptor, Object, Appendable)`*

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Descriptors.FieldDescriptor` |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### printFieldToString(Descriptors.FieldDescriptor field, Object value) (deprecated)

    public static String printFieldToString(Descriptors.FieldDescriptor field, Object value)

**Deprecated.** *Use `printer().printFieldToString(FieldDescriptor, Object)`*

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Descriptors.FieldDescriptor` |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

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

### printFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) (deprecated)

    public static void printFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output)

**Deprecated.** *Use `printer().printFieldValue(FieldDescriptor, Object, Appendable)`*

Outputs a textual representation of the value of given field value.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Descriptors.FieldDescriptor` the descriptor of the field |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` the value of the field |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` the output to which to append the formatted value |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if the value is not appropriate for the given field descriptor |

### printToString(MessageOrBuilder message) (deprecated)

    public static String printToString(MessageOrBuilder message)

**Deprecated.** *Use `message.toString()`*

Like `print()`, but writes directly to a `String` and returns it.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |

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

### printToString(UnknownFieldSet fields) (deprecated)

    public static String printToString(UnknownFieldSet fields)

**Deprecated.** *Use [UnknownFieldSet#toString()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet#com_google_protobuf_UnknownFieldSet_toString__)*

Like `print()`, but writes directly to a `String` and returns it.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet` |

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

### printToUnicodeString(MessageOrBuilder message) (deprecated)

    public static String printToUnicodeString(MessageOrBuilder message)

**Deprecated.** *Use `printer().escapingNonAscii(false).printToString(MessageOrBuilder)`*

Same as `printToString()`, except that non-ASCII characters in string type fields are not
escaped in backslash+octals.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |

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

### printToUnicodeString(UnknownFieldSet fields) (deprecated)

    public static String printToUnicodeString(UnknownFieldSet fields)

**Deprecated.** *Use `printer().escapingNonAscii(false).printToString(UnknownFieldSet)`*

Same as `printToString()`, except that non-ASCII characters in string type fields are
not escaped in backslash+octals.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet` |

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

### printUnicode(MessageOrBuilder message, Appendable output) (deprecated)

    public static void printUnicode(MessageOrBuilder message, Appendable output)

**Deprecated.** *Use `printer().escapingNonAscii(false).print(MessageOrBuilder, Appendable)`*

Same as `print()`, except that non-ASCII characters are not escaped.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### printUnicode(UnknownFieldSet fields, Appendable output) (deprecated)

    public static void printUnicode(UnknownFieldSet fields, Appendable output)

**Deprecated.** *Use `printer().escapingNonAscii(false).print(UnknownFieldSet, Appendable)`*

Same as `print()`, except that non-ASCII characters are not escaped.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet` |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### printUnicodeFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) (deprecated)

    public static void printUnicodeFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output)

**Deprecated.** *Use `printer().escapingNonAscii(false).printFieldValue(FieldDescriptor,
Object, Appendable)`*

Outputs a unicode textual representation of the value of given field value.

Same as `printFieldValue()`, except that non-ASCII characters in string type fields
are not escaped in backslash+octals.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Descriptors.FieldDescriptor` the descriptor of the field |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` the value of the field |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` the output to which to append the formatted value |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if the value is not appropriate for the given field descriptor |

### printUnknownFieldValue(int tag, Object value, Appendable output)

    public static void printUnknownFieldValue(int tag, Object value, Appendable output)

Outputs a textual representation of the value of an unknown field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `tag` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the field's tag number |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` the value of the field |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` the output to which to append the formatted value |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if the value is not appropriate for the given field descriptor |

### printer()

    public static TextFormat.Printer printer()

Printer instance which escapes non-ASCII characters.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.Printer` |   |

### shortDebugString(Descriptors.FieldDescriptor field, Object value) (deprecated)

    public static String shortDebugString(Descriptors.FieldDescriptor field, Object value)

**Deprecated.** *Use `printer().shortDebugString(FieldDescriptor, Object)`*

Generates a human readable form of the field, useful for debugging and other purposes, with
no newline characters.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Descriptors.FieldDescriptor` |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

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

### shortDebugString(MessageOrBuilder message)

    public static String shortDebugString(MessageOrBuilder message)

Generates a human readable form of this message, useful for debugging and other purposes, with
no newline characters. This is just a trivial wrapper around
[TextFormat.Printer#shortDebugString(MessageOrBuilder)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.Printer#com_google_protobuf_TextFormat_Printer_shortDebugString_com_google_protobuf_MessageOrBuilder_).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |

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

### shortDebugString(UnknownFieldSet fields) (deprecated)

    public static String shortDebugString(UnknownFieldSet fields)

**Deprecated.** *Use `printer().shortDebugString(UnknownFieldSet)`*

Generates a human readable form of the unknown fields, useful for debugging and other
purposes, with no newline characters.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet` |

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

### unescapeBytes(CharSequence charString)

    public static ByteString unescapeBytes(CharSequence charString)

Un-escape a byte sequence as escaped using [#escapeBytes(ByteString)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat#com_google_protobuf_TextFormat_escapeBytes_com_google_protobuf_ByteString_). Two-digit hex
escapes (starting with "\\x") are also recognized.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.InvalidEscapeSequenceException` |   |

### unsignedToString(int value)

    public static String unsignedToString(int value)

Convert an unsigned 32-bit integer to a string.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

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

### unsignedToString(long value)

    public static String unsignedToString(long value)

Convert an unsigned 64-bit integer to a string.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

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