Class BufferBody

  • All Implemented Interfaces:
    Body

    class BufferBody
    extends java.lang.Object
    implements Body
    The Body interface is used to represent the body of a HTTP entity. It contains the information that is delivered with the request. The body is represented by a stream of bytes. In order to access the entity body this interface provides a stream which can be used to read it. Also, should the message be encoded as a multipart message the individual parts can be read using the Attachment instance for it.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Buffer buffer
      This is usd to hold the bytes representing the HTTP body.
      private PartSeries series
      This is used to hold the attachments for the HTTP body.
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferBody()
      Constructor for the BufferBody object.
      BufferBody​(Buffer buffer)
      Constructor for the BufferBody object.
      BufferBody​(Buffer buffer, PartSeries series)
      Constructor for the BufferBody object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getContent()
      This will acquire the contents of the body in UTF-8.
      java.lang.String getContent​(java.lang.String charset)
      This will acquire the contents of the body in the specified charset.
      java.io.InputStream getInputStream()
      This is used to acquire the contents of the body as a stream.
      Part getPart​(java.lang.String name)
      This method is used to acquire a Part from the HTTP request using a known name for the part.
      java.util.List<Part> getParts()
      This method is used to get all Part objects that are associated with the request.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • series

        private final PartSeries series
        This is used to hold the attachments for the HTTP body.
      • buffer

        private final Buffer buffer
        This is usd to hold the bytes representing the HTTP body.
    • Constructor Detail

      • BufferBody

        public BufferBody()
        Constructor for the BufferBody object. This is used to create a body that represents a HTTP payload. The body enables the payload to be either read in a stream or as an encoded string. Also the attachments are available.
      • BufferBody

        public BufferBody​(Buffer buffer)
        Constructor for the BufferBody object. This is used to create a body that represents a HTTP payload. The body enables the payload to be either read in a stream or as an encoded string. Also the attachments are available.
        Parameters:
        buffer - this is the buffer representing the body
      • BufferBody

        public BufferBody​(Buffer buffer,
                          PartSeries series)
        Constructor for the BufferBody object. This is used to create a body that represents a HTTP payload. The body enables the payload to be either read in a stream or as an encoded string. Also the attachments are available.
        Parameters:
        buffer - this is the buffer representing the body
        series - this is the list of parts for this body
    • Method Detail

      • getPart

        public Part getPart​(java.lang.String name)
        This method is used to acquire a Part from the HTTP request using a known name for the part. This is typically used when there is a file upload with a multipart POST request. All parts that are not files can be acquired as string values from the attachment object.
        Specified by:
        getPart in interface Body
        Parameters:
        name - this is the name of the part object to acquire
        Returns:
        the named part or null if the part does not exist
      • getParts

        public java.util.List<Part> getParts()
        This method is used to get all Part objects that are associated with the request. Each attachment contains the body and headers associated with it. If the request is not a multipart POST request then this will return an empty list.
        Specified by:
        getParts in interface Body
        Returns:
        the list of parts associated with this request
      • getContent

        public java.lang.String getContent()
                                    throws java.io.IOException
        This will acquire the contents of the body in UTF-8. If there is no content encoding and the user of the request wants to deal with the body as a string then this method can be used. It will simply create a UTF-8 string using the body bytes.
        Specified by:
        getContent in interface Body
        Returns:
        returns a UTF-8 string representation of the body
        Throws:
        java.io.IOException
      • getContent

        public java.lang.String getContent​(java.lang.String charset)
                                    throws java.io.IOException
        This will acquire the contents of the body in the specified charset. Typically this will be given the charset as taken from the HTTP Content-Type header. Although any encoding can be specified to convert the body to a string representation.
        Specified by:
        getContent in interface Body
        Returns:
        returns an encoded string representation of the body
        Throws:
        java.io.IOException
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        This is used to acquire the contents of the body as a stream. Each time this method is invoked a new stream is created that will read the contents of the body from the first byte. This ensures that the stream can be acquired several times without any issues arising from previous reads.
        Specified by:
        getInputStream in interface Body
        Returns:
        this returns a new string used to read the body
        Throws:
        java.io.IOException