Package org.opensearch.client.util
Class OpenSearchRequestBodyBuffer
java.lang.Object
org.opensearch.client.util.OpenSearchRequestBodyBuffer
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.
-
Constructor Summary
ConstructorsConstructorDescriptionOpenSearchRequestBodyBuffer(JsonpMapper mapper, int requestCompressionSize) Create a request body buffer -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContent(Object content) Add some content to the buffer.voidclose()This call finalizes the buffer.byte[]Get the contents of this buffer as a byte array.Get the value of the Content-Encoding header that should be sent along with this buffer, or null if there shouldn't be one.longGet the value of the Content-Length header that should be sent along with this buffer.Get the value of the Content-Type header that should be sent along with this buffer.Get the contents of this buffer as a new InputStream.booleanbooleanisNdJson()
-
Constructor Details
-
OpenSearchRequestBodyBuffer
Create a request body buffer- Parameters:
mapper- mapper used to serialize the contentrequestCompressionSize- When the captured data exceeds this size, it will be automatically compressed. Pass Integer.MAX_VALUE to prevent compression
-
-
Method Details
-
addContent
Add some content to the buffer. If the buffer already contains some data, or if the provided object implementsNdJsonpSerializable, then the buffer will contain multiple objects in newline-delimited JSON format.- Parameters:
content- The new content object to add- Throws:
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
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
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
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
This call finalizes the buffer. After this call, any attempt to add more content will throw an IOException.- Throws:
IOException
-