Class UrlEncodedSerializer


  • public class UrlEncodedSerializer
    extends Serializer
    Serializer for handling URL encoded form data, also commonly used in open web protocols like OAuth2. It will operate on the content as one entry per line, and stop whenever a newline or end of input is encountered. Content not simply serializable to url-encoded string will be first JSON serialized, then URL-encoded.
    • Constructor Detail

      • UrlEncodedSerializer

        public UrlEncodedSerializer()
    • Method Detail

      • serialize

        public <Message extends PMessage<Message>> int serialize​(@Nonnull
                                                                 java.io.OutputStream output,
                                                                 @Nonnull
                                                                 PMessageOrBuilder<Message> message)
                                                          throws java.io.IOException
        Description copied from class: Serializer
        Serialize a message.
        Specified by:
        serialize in class Serializer
        Type Parameters:
        Message - The message type.
        Parameters:
        output - The output stream to write to.
        message - The message to write.
        Returns:
        The number of bytes written to the output stream.
        Throws:
        java.io.IOException - If writing or serialization failed.
      • serialize

        public <Message extends PMessage<Message>> int serialize​(@Nonnull
                                                                 java.io.OutputStream output,
                                                                 @Nonnull
                                                                 PServiceCall<Message> call)
                                                          throws java.io.IOException
        Description copied from class: Serializer
        Serialize a service call.
        Specified by:
        serialize in class Serializer
        Type Parameters:
        Message - The message type contained in the service call.
        Parameters:
        output - The output stream to write to.
        call - The service call to write.
        Returns:
        The number of bytes written to the output stream.
        Throws:
        java.io.IOException - If writing or serialization failed.
      • serialize

        public <Message extends PMessage<Message>> java.lang.String serialize​(@Nonnull
                                                                              PMessageOrBuilder<Message> message)
                                                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • deserialize

        @Nonnull
        public <Message extends PMessage<Message>> Message deserialize​(@Nonnull
                                                                       java.io.InputStream input,
                                                                       @Nonnull
                                                                       PMessageDescriptor<Message> descriptor)
                                                                throws java.io.IOException
        Description copied from class: Serializer
        Deserialize a message.
        Specified by:
        deserialize in class Serializer
        Type Parameters:
        Message - The message type.
        Parameters:
        input - The input stream to read from.
        descriptor - The descriptor of the message to read.
        Returns:
        The message read.
        Throws:
        java.io.IOException - If reading or deserialization failed.
      • deserialize

        @Nonnull
        public <Message extends PMessage<Message>> PServiceCall<Message> deserialize​(@Nonnull
                                                                                     java.io.InputStream input,
                                                                                     @Nonnull
                                                                                     PService service)
                                                                              throws java.io.IOException
        Description copied from class: Serializer
        Deserialize a service call.
        Specified by:
        deserialize in class Serializer
        Type Parameters:
        Message - The message type contained in the returned service call.
        Parameters:
        input - The input stream to read from.
        service - The service definition to read for.
        Returns:
        The service call read.
        Throws:
        java.io.IOException - If reading or deserialization failed.
      • binaryProtocol

        public boolean binaryProtocol()
        Specified by:
        binaryProtocol in class Serializer
        Returns:
        True if the protocol of the serializer is "binary" a.k.a. unreadable to most humans.
      • verifyEndOfContent

        public void verifyEndOfContent​(@Nonnull
                                       java.io.InputStream input)
                                throws java.io.IOException
        Description copied from class: Serializer
        Verify that the input stream does not contain any more readable content and close the stream. Throws exception if unable to verify, or the streams contains any meaningful content.
        Specified by:
        verifyEndOfContent in class Serializer
        Parameters:
        input - The input stream to check.
        Throws:
        java.io.IOException - If unable to read from stream or stream contains meaningful content.
      • mediaType

        @Nonnull
        public java.lang.String mediaType()
        Specified by:
        mediaType in class Serializer
        Returns:
        Media type of the content generated by the serializer. Can be used for Content-Type and Accept HTTP headers, MIME type etc.