Package org.opensearch.client.util
Class OpenSearchRequestBodyBuffer
- java.lang.Object
-
- org.opensearch.client.util.OpenSearchRequestBodyBuffer
-
public class OpenSearchRequestBodyBuffer extends java.lang.ObjectSerializes 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 variousOpenSearchTransportimplementations.Request bodies can be automatically compressed when they exceed a given size.
-
-
Constructor Summary
Constructors Constructor Description OpenSearchRequestBodyBuffer(JsonpMapper mapper, int requestCompressionSize)Create a request body buffer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContent(java.lang.Object content)Add some content to the buffer.voidclose()This call finalizes the buffer.byte[]getByteArray()Get the contents of this buffer as a byte array.java.lang.StringgetContentEncoding()Get the value of the Content-Encoding header that should be sent along with this buffer, or null if there shouldn't be one.longgetContentLength()Get the value of the Content-Length header that should be sent along with this buffer.java.lang.StringgetContentType()Get the value of the Content-Type header that should be sent along with this buffer.java.io.InputStreamgetInputStream()Get the contents of this buffer as a new InputStream.booleanisCompressed()booleanisNdJson()
-
-
-
Constructor Detail
-
OpenSearchRequestBodyBuffer
public OpenSearchRequestBodyBuffer(JsonpMapper mapper, int requestCompressionSize)
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 Detail
-
addContent
public void addContent(java.lang.Object content) throws java.io.IOExceptionAdd 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:
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.IOExceptionThis call finalizes the buffer. After this call, any attempt to add more content will throw an IOException.- Throws:
java.io.IOException
-
-