Package com.langfuse.client.core
Class InputStreamRequestBody
java.lang.Object
okhttp3.RequestBody
com.langfuse.client.core.InputStreamRequestBody
public class InputStreamRequestBody
extends okhttp3.RequestBody
A custom implementation of OkHttp's RequestBody that wraps an InputStream.
This class allows streaming of data from an InputStream directly to an HTTP request body,
which is useful for file uploads or sending large amounts of data without loading it all into memory.
-
Nested Class Summary
Nested classes/interfaces inherited from class okhttp3.RequestBody
okhttp3.RequestBody.Companion -
Field Summary
Fields inherited from class okhttp3.RequestBody
Companion -
Constructor Summary
ConstructorsConstructorDescriptionInputStreamRequestBody(okhttp3.MediaType contentType, InputStream inputStream) Constructs an InputStreamRequestBody with the specified content type and input stream. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the content length of this request body, if known.okhttp3.MediaTypeReturns the content type of this request body.voidwriteTo(okio.BufferedSink sink) Writes the content of the InputStream to the given BufferedSink.Methods inherited from class okhttp3.RequestBody
create, create, create, create, create, create, create, create, create, create, create, create, create, isDuplex, isOneShot
-
Constructor Details
-
InputStreamRequestBody
Constructs an InputStreamRequestBody with the specified content type and input stream.- Parameters:
contentType- the MediaType of the content, or null if not knowninputStream- the InputStream containing the data to be sent- Throws:
NullPointerException- if inputStream is null
-
-
Method Details
-
contentType
@Nullable public okhttp3.MediaType contentType()Returns the content type of this request body.- Specified by:
contentTypein classokhttp3.RequestBody- Returns:
- the MediaType of the content, or null if not specified
-
contentLength
Returns the content length of this request body, if known. This method attempts to determine the length using the InputStream's available() method, which may not always accurately reflect the total length of the stream.- Overrides:
contentLengthin classokhttp3.RequestBody- Returns:
- the content length, or -1 if the length is unknown
- Throws:
IOException- if an I/O error occurs
-
writeTo
Writes the content of the InputStream to the given BufferedSink. This method is responsible for transferring the data from the InputStream to the network request.- Specified by:
writeToin classokhttp3.RequestBody- Parameters:
sink- the BufferedSink to write the content to- Throws:
IOException- if an I/O error occurs during writing
-