Class TextFormat.Printer

  • Enclosing class:
    TextFormat

    public static final class TextFormat.Printer
    extends java.lang.Object
    Helper class for converting protobufs to text.
    • Method Detail

      • escapingNonAscii

        public TextFormat.Printer escapingNonAscii​(boolean escapeNonAscii)
        Return a new Printer instance with the specified escape mode.
        Parameters:
        escapeNonAscii - If true, the new Printer will escape non-ASCII characters (this is the default behavior. If false, the new Printer will print non-ASCII characters as is. In either case, the new Printer still escapes newlines and quotes in strings.
        Returns:
        a new Printer that clones all other configurations from the current TextFormat.Printer, with the escape mode set to the given parameter.
      • usingExtensionRegistry

        public TextFormat.Printer usingExtensionRegistry​(com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        Creates a new TextFormat.Printer using the given extensionRegistry. The new Printer clones all other configurations from the current TextFormat.Printer.
        Throws:
        java.lang.IllegalArgumentException - if a registry is already set.
      • usingShortRepeatedPrimitives

        public TextFormat.Printer usingShortRepeatedPrimitives​(boolean useShortRepeatedPrimitives)
        Return a new Printer instance that outputs primitive repeated fields in short notation
        Parameters:
        useShortRepeatedPrimitives - If true, repeated fields with a primitive type are printed using the short hand notation with comma-delimited field values in square brackets.
        Returns:
        a new Printer that clones all other configurations from the current TextFormat.Printer, with the useShortRepeatedPrimitives mode set to the given parameter.
      • emittingSingleLine

        public TextFormat.Printer emittingSingleLine​(boolean singleLine)
        Return a new Printer instance with the specified line formatting status.
        Parameters:
        singleLine - If true, the new Printer will output no newline characters.
        Returns:
        a new Printer that clones all other configurations from the current TextFormat.Printer, with the singleLine mode set to the given parameter.
      • print

        public void print​(MessageOrBuilder message,
                          java.lang.Appendable output)
                   throws java.io.IOException
        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)
        Throws:
        java.io.IOException
      • print

        public void print​(UnknownFieldSet fields,
                          java.lang.Appendable output)
                   throws java.io.IOException
        Outputs a textual representation of fields to output.
        Throws:
        java.io.IOException
      • printField

        public void printField​(Descriptors.FieldDescriptor field,
                               java.lang.Object value,
                               java.lang.Appendable output)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • printFieldValue

        public void printFieldValue​(Descriptors.FieldDescriptor field,
                                    java.lang.Object value,
                                    java.lang.Appendable output)
                             throws java.io.IOException
        Outputs a textual representation of the value of given field value.
        Parameters:
        field - the descriptor of the field
        value - the value of the field
        output - the output to which to append the formatted value
        Throws:
        java.lang.ClassCastException - if the value is not appropriate for the given field descriptor
        java.io.IOException - if there is an exception writing to the output
      • printToString

        public java.lang.String printToString​(MessageOrBuilder message)
        Like print(), but writes directly to a String and returns it.
      • printToString

        public java.lang.String printToString​(UnknownFieldSet fields)
        Like print(), but writes directly to a String and returns it.
      • shortDebugString

        @Deprecated
        public java.lang.String shortDebugString​(MessageOrBuilder message)
        Deprecated.
        Use this.emittingSingleLine(true).printToString(MessageOrBuilder)
        Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.
      • shortDebugString

        @Deprecated
        @InlineMe(replacement="this.emittingSingleLine(true).printFieldToString(field, value)")
        public java.lang.String shortDebugString​(Descriptors.FieldDescriptor field,
                                                 java.lang.Object value)
        Deprecated.
        Use this.emittingSingleLine(true).printFieldToString(FieldDescriptor, Object)
        Generates a human readable form of the field, useful for debugging and other purposes, with no newline characters.
      • shortDebugString

        @Deprecated
        @InlineMe(replacement="this.emittingSingleLine(true).printToString(fields)")
        public java.lang.String shortDebugString​(UnknownFieldSet fields)
        Deprecated.
        Use this.emittingSingleLine(true).printToString(UnknownFieldSet)
        Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.