> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cdp.coinbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# InputStreamRequestBody

> A custom implementation of OkHttp's RequestBody that wraps an InputStream.

Package: [`com.coinbase.cdp.core`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/core/index)

```java theme={null}
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.

## Constructor Details

### `InputStreamRequestBody`

```java theme={null}
public InputStreamRequestBody(okhttp3.MediaType contentType, InputStream inputStream)
```

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`

```java theme={null}
public okhttp3.MediaType contentType()
```

Returns the content type of this request body.

**Returns:**

`okhttp3.MediaType` - the MediaType of the content, or null if not specified

### `contentLength`

```java theme={null}
public long contentLength()
```

Returns `-1` because a general InputStream has no reliable total length.

**Returns:**

`long` - `-1`, indicating an unknown content length

### `writeTo`

```java theme={null}
public void writeTo(okio.BufferedSink sink) throws IOException
```

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`
