Package com.flagright.api.core
Class InputStreamRequestBody
- java.lang.Object
-
- okhttp3.RequestBody
-
- com.flagright.api.core.InputStreamRequestBody
-
public class InputStreamRequestBody extends okhttp3.RequestBodyA 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.
-
-
Constructor Summary
Constructors Constructor Description InputStreamRequestBody(okhttp3.MediaType contentType, java.io.InputStream inputStream)Constructs an InputStreamRequestBody with the specified content type and input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcontentLength()Returns the content length of this request body, if known.okhttp3.MediaTypecontentType()Returns the content type of this request body.voidwriteTo(okio.BufferedSink sink)Writes the content of the InputStream to the given BufferedSink.
-
-
-
Constructor Detail
-
InputStreamRequestBody
public InputStreamRequestBody(@Nullable okhttp3.MediaType contentType, java.io.InputStream inputStream)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:
java.lang.NullPointerException- if inputStream is null
-
-
Method Detail
-
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
public long contentLength() throws java.io.IOExceptionReturns 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:
java.io.IOException- if an I/O error occurs
-
writeTo
public void writeTo(okio.BufferedSink sink) throws java.io.IOExceptionWrites 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:
java.io.IOException- if an I/O error occurs during writing
-
-