# BidirectionalStream.Builder


```
public abstract class BidirectionalStream.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream`s. Allows configuring stream before constructing it via `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#build()`. Created by `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#newBidirectionalStreamBuilder(java.lang.String,org.chromium.net.BidirectionalStream.Callback,java.util.concurrent.Executor)`.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_HIGHEST() = 4` Highest stream priority. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_IDLE() = 0` Lowest stream priority. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_LOW() = 2` Low stream priority. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_LOWEST() = 1` Very low stream priority. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_MEDIUM() = 3` Medium stream priority. |

| ### Public constructors |
|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#Builder()()` |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#addHeader(java.lang.String,java.lang.String)(https://developer.android.com/reference/java/lang/String.html header, https://developer.android.com/reference/java/lang/String.html value)` Adds a request header. |
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#addRequestAnnotation(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html annotation)` Associates the annotation object with this request. |
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#bindToNetwork(long)(long networkHandle)` Binds the request to the specified network handle. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#build()()` Creates a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream` using configuration from this `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder`. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#delayRequestHeadersUntilFirstFlush(boolean)( boolean delayRequestHeadersUntilFirstFlush )` Delays sending request headers until `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream#flush()` is called. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setHttpMethod(java.lang.String)(https://developer.android.com/reference/java/lang/String.html method)` Sets the HTTP method for the request. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setPriority(int)(int priority)` Sets priority of the stream which should be one of the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_IDLE()` values. |
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setTrafficStatsTag(int)(int tag)` Sets `https://developer.android.com/reference/android/net/TrafficStats.html` tag to use when accounting socket traffic caused by this request. |
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setTrafficStatsUid(int)(int uid)` Sets specific UID to use when accounting socket traffic caused by this request. |

## Constants

### STREAM_PRIORITY_HIGHEST

```
public static final int STREAM_PRIORITY_HIGHEST = 4
```

Highest stream priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setPriority(int)`.

### STREAM_PRIORITY_IDLE

```
public static final int STREAM_PRIORITY_IDLE = 0
```

Lowest stream priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setPriority(int)`.

### STREAM_PRIORITY_LOW

```
public static final int STREAM_PRIORITY_LOW = 2
```

Low stream priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setPriority(int)`.

### STREAM_PRIORITY_LOWEST

```
public static final int STREAM_PRIORITY_LOWEST = 1
```

Very low stream priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setPriority(int)`.

### STREAM_PRIORITY_MEDIUM

```
public static final int STREAM_PRIORITY_MEDIUM = 3
```

Medium stream priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#setPriority(int)`. This is the default priority given to the stream.

## Public constructors

### Builder

```
public Builder()
```

## Public methods

### addHeader

```
public abstract BidirectionalStream.Builder addHeader(String header, String value)
```

Adds a request header. Returns builder to facilitate chaining.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html header` | the header name |
| `https://developer.android.com/reference/java/lang/String.html value` | the header value |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining |

### addRequestAnnotation

```
public BidirectionalStream.Builder addRequestAnnotation(Object annotation)
```

Associates the annotation object with this request. May add more than one. Passed through to a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener`, see `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo#getAnnotations()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html annotation` | an object to pass on to the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener` with a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo`. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining. |

### bindToNetwork

```
public BidirectionalStream.Builder bindToNetwork(long networkHandle)
```

Binds the request to the specified network handle. Cronet will send this request only using the network associated to this handle. If this network disconnects the request will fail, the exact error will depend on the stage of request processing when the network disconnects. Network handles can be obtained through `Network#getNetworkHandle`. Only available starting from Android Marshmallow.

| Parameters |
|---|---|
| `long networkHandle` | the network handle to bind the request to. Specify `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#UNBIND_NETWORK_HANDLE()` to unbind. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining. |

### build

```
public abstract BidirectionalStream build()
```

Creates a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream` using configuration from this `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder`. The returned `BidirectionalStream` can then be started by calling `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream#start()`.

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream` | constructed `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream` using configuration from this `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` |

### delayRequestHeadersUntilFirstFlush

```
public abstract BidirectionalStream.Builder delayRequestHeadersUntilFirstFlush(
    boolean delayRequestHeadersUntilFirstFlush
)
```

Delays sending request headers until `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream#flush()` is called. This flag is currently only respected when QUIC is negotiated. When true, QUIC will send request header frame along with data frame(s) as a single packet when possible.

| Parameters |
|---|---|
| `boolean delayRequestHeadersUntilFirstFlush` | if true, sending request headers will be delayed until flush() is called. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining. |

### setHttpMethod

```
public abstract BidirectionalStream.Builder setHttpMethod(String method)
```

Sets the HTTP method for the request. Returns builder to facilitate chaining.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html method` | the method to use for request. Default is 'POST' |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining |

### setPriority

```
public abstract BidirectionalStream.Builder setPriority(int priority)
```

Sets priority of the stream which should be one of the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_IDLE()` values. The stream is given `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_MEDIUM()` priority if this method is not called.

| Parameters |
|---|---|
| `int priority` | priority of the stream which should be one of the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder#STREAM_PRIORITY_IDLE()` values. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining. |

### setTrafficStatsTag

```
public BidirectionalStream.Builder setTrafficStatsTag(int tag)
```

Sets `https://developer.android.com/reference/android/net/TrafficStats.html` tag to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/android/net/TrafficStats.html` for more information. If no tag is set (e.g. this method isn't called), then Android accounts for the socket traffic caused by this request as if the tag value were set to 0.

**NOTE:**Setting a tag disallows sharing of sockets with requests with other tags, which may adversely effect performance by prohibiting connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2 and QUIC) will only be allowed if all requests have the same socket tag.

| Parameters |
|---|---|
| `int tag` | the tag value used to when accounting for socket traffic caused by this request. Tags between 0xFFFFFF00 and 0xFFFFFFFF are reserved and used internally by system services like `https://developer.android.com/reference/android/app/DownloadManager.html` when performing traffic on behalf of an application. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining. |

### setTrafficStatsUid

```
public BidirectionalStream.Builder setTrafficStatsUid(int uid)
```

Sets specific UID to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/android/net/TrafficStats.html` for more information. Designed for use when performing an operation on behalf of another application. Caller must hold `
MODIFY_NETWORK_ACCOUNTING` permission. By default traffic is attributed to UID of caller.

**NOTE:**Setting a UID disallows sharing of sockets with requests with other UIDs, which may adversely effect performance by prohibiting connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2 and QUIC) will only be allowed if all requests have the same UID set.

| Parameters |
|---|---|
| `int uid` | the UID to attribute socket traffic caused by this request. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Builder` | the builder to facilitate chaining. |