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

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
extensionRegistry
protoClass
Class < T >
Returns
Type
Description
T

the parsed message, guaranteed initialized

Exceptions
Type
Description

<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
protoClass
Class < T >
Returns
Type
Description
T

the parsed message, guaranteed initialized

Exceptions
Type
Description

escapeBytes(byte[] input)

  public 
  
 static 
  
 String 
  
 escapeBytes 
 ( 
 byte 
 [] 
  
 input 
 ) 
 

Like #escapeBytes(ByteString) , but used for byte array.

Parameter
Name
Description
input
byte []
Returns
Type
Description

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
Returns
Type
Description

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
Returns
Type
Description

getParser()

  public 
  
 static 
  
 TextFormat 
 . 
 Parser 
  
 getParser 
 () 
 

Return a Parser instance which can parse text-format messages. The returned instance is thread-safe.

Returns
Type
Description

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
extensionRegistry
builder
Exceptions
Type
Description

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
builder
Exceptions
Type
Description

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
extensionRegistry
builder
Exceptions
Type
Description

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
builder
Exceptions
Type
Description

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
output
Exceptions
Type
Description

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
output
Exceptions
Type
Description

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
value
output
Exceptions
Type
Description

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
value
Returns
Type
Description

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
Descriptors.FieldDescriptor

the descriptor of the field

value
Object

the value of the field

output
Appendable

the output to which to append the formatted value

Exceptions
Type
Description

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
Returns
Type
Description

printToString(UnknownFieldSet fields) (deprecated)

  public 
  
 static 
  
 String 
  
 printToString 
 ( 
 UnknownFieldSet 
  
 fields 
 ) 
 

Deprecated. Use UnknownFieldSet#toString()

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

Parameter
Name
Description
Returns
Type
Description

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
Returns
Type
Description

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
Returns
Type
Description

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
output
Exceptions
Type
Description

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
output
Exceptions
Type
Description

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
Descriptors.FieldDescriptor

the descriptor of the field

value
Object

the value of the field

output
Appendable

the output to which to append the formatted value

Exceptions
Type
Description

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
int

the field's tag number

value
Object

the value of the field

output
Appendable

the output to which to append the formatted value

Exceptions
Type
Description

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

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
value
Returns
Type
Description

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) .

Parameter
Name
Description
Returns
Type
Description

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
Returns
Type
Description

unescapeBytes(CharSequence charString)

  public 
  
 static 
  
 ByteString 
  
 unescapeBytes 
 ( 
 CharSequence 
  
 charString 
 ) 
 

Un-escape a byte sequence as escaped using #escapeBytes(ByteString) . Two-digit hex escapes (starting with "\x") are also recognized.

Parameter
Name
Description
charString
Returns
Type
Description
Exceptions
Type
Description

unsignedToString(int value)

  public 
  
 static 
  
 String 
  
 unsignedToString 
 ( 
 int 
  
 value 
 ) 
 

Convert an unsigned 32-bit integer to a string.

Parameter
Name
Description
value
int
Returns
Type
Description

unsignedToString(long value)

  public 
  
 static 
  
 String 
  
 unsignedToString 
 ( 
 long 
  
 value 
 ) 
 

Convert an unsigned 64-bit integer to a string.

Parameter
Name
Description
value
Returns
Type
Description
Design a Mobile Site
View Site in Mobile | Classic
Share by: