Skip to main content
Package: com.coinbase.cdp.core
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.

Constructor Details

InputStreamRequestBody

Constructs an InputStreamRequestBody with the specified content type and input stream. Parameters: contentType (okhttp3.MediaType) - the MediaType of the content, or null if not known inputStream (InputStream) - the InputStream containing the data to be sent Throws: [NullPointerException](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NullPointerException.html "class or interface in java.lang") - if inputStream is null

Method Details

contentType

Returns the content type of this request body. Returns: okhttp3.MediaType - the MediaType of the content, or null if not specified

contentLength

Returns -1 because a general InputStream has no reliable total length. Returns: long - -1, indicating an unknown content length

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. Parameters: sink (okio.BufferedSink) - the BufferedSink to write the content to Throws: [IOException](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/IOException.html "class or interface in java.io") - if an I/O error occurs during writing Returns: void