Class OpenSearchRequestBodyBuffer


  • public class OpenSearchRequestBodyBuffer
    extends java.lang.Object
    Serializes and captures an OpenSearch request body, and then provides access to it in convenient forms for HTTP requests. This is a utility class for use by various OpenSearchTransport implementations.

    Request bodies can be automatically compressed when they exceed a given size.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addContent​(java.lang.Object content)
      Add some content to the buffer.
      void close()
      This call finalizes the buffer.
      byte[] getByteArray()
      Get the contents of this buffer as a byte array.
      java.lang.String getContentEncoding()
      Get the value of the Content-Encoding header that should be sent along with this buffer, or null if there shouldn't be one.
      long getContentLength()
      Get the value of the Content-Length header that should be sent along with this buffer.
      java.lang.String getContentType()
      Get the value of the Content-Type header that should be sent along with this buffer.
      java.io.InputStream getInputStream()
      Get the contents of this buffer as a new InputStream.
      boolean isCompressed()  
      boolean isNdJson()  
      • Methods inherited from class java.lang.Object

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

      • OpenSearchRequestBodyBuffer

        public OpenSearchRequestBodyBuffer​(JsonpMapper mapper,
                                           int requestCompressionSize)
        Create a request body buffer
        Parameters:
        mapper - mapper used to serialize the content
        requestCompressionSize - When the captured data exceeds this size, it will be automatically compressed. Pass Integer.MAX_VALUE to prevent compression
    • Method Detail

      • addContent

        public void addContent​(java.lang.Object content)
                        throws java.io.IOException
        Add some content to the buffer. If the buffer already contains some data, or if the provided object implements NdJsonpSerializable, then the buffer will contain multiple objects in newline-delimited JSON format.
        Parameters:
        content - The new content object to add
        Throws:
        java.io.IOException
      • isCompressed

        public boolean isCompressed()
        Returns:
        true if the content has been compressed
      • isNdJson

        public boolean isNdJson()
        Returns:
        true if this buffer contains multiple newline-delimited objects.
      • getContentEncoding

        @CheckForNull
        public java.lang.String getContentEncoding()
        Get the value of the Content-Encoding header that should be sent along with this buffer, or null if there shouldn't be one.
      • getContentType

        @Nonnull
        public java.lang.String getContentType()
        Get the value of the Content-Type header that should be sent along with this buffer.
      • getContentLength

        public long getContentLength()
        Get the value of the Content-Length header that should be sent along with this buffer.

        This call finalizes the buffer. After this call, any attempt to add more content will throw an IOException.

        Returns:
        The length of the buffered content
      • getByteArray

        public byte[] getByteArray()
        Get the contents of this buffer as a byte array.

        This call finalizes the buffer. After this call, any attempt to add more content will throw an IOException.

        Returns:
        The buffered data
      • getInputStream

        public java.io.InputStream getInputStream()
        Get the contents of this buffer as a new InputStream.

        Calls to this method are cheap, since all the new streams will share the same underlying array

        This call finalizes the buffer. After this call, any attempt to add more content will throw an IOException.

        Returns:
        The buffered data
      • close

        public void close()
                   throws java.io.IOException
        This call finalizes the buffer. After this call, any attempt to add more content will throw an IOException.
        Throws:
        java.io.IOException