BidirectionalStream.Builder

public abstract class BidirectionalStream.Builder


Builder for BidirectionalStreams. Allows configuring stream before constructing it via build. Created by newBidirectionalStreamBuilder.

Summary

Constants

static final int

Highest stream priority.

static final int

Lowest stream priority.

static final int

Low stream priority.

static final int

Very low stream priority.

static final int

Medium stream priority.

Public constructors

Public methods

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

Adds a request header.

BidirectionalStream.Builder

Associates the annotation object with this request.

BidirectionalStream.Builder
bindToNetwork(long networkHandle)

Binds the request to the specified network handle.

abstract BidirectionalStream

Creates a BidirectionalStream using configuration from this Builder.

abstract BidirectionalStream.Builder
delayRequestHeadersUntilFirstFlush(
    boolean delayRequestHeadersUntilFirstFlush
)

Delays sending request headers until flush is called.

abstract BidirectionalStream.Builder

Sets the HTTP method for the request.

abstract BidirectionalStream.Builder
setPriority(int priority)

Sets priority of the stream which should be one of the STREAM_PRIORITY_* values.

BidirectionalStream.Builder

Sets android.net.TrafficStats tag to use when accounting socket traffic caused by this request.

BidirectionalStream.Builder

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 setPriority.

STREAM_PRIORITY_IDLE

public static final int STREAM_PRIORITY_IDLE = 0

Lowest stream priority. Passed to setPriority.

STREAM_PRIORITY_LOW

public static final int STREAM_PRIORITY_LOW = 2

Low stream priority. Passed to setPriority.

STREAM_PRIORITY_LOWEST

public static final int STREAM_PRIORITY_LOWEST = 1

Very low stream priority. Passed to setPriority.

STREAM_PRIORITY_MEDIUM

public static final int STREAM_PRIORITY_MEDIUM = 3

Medium stream priority. Passed to setPriority. 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
String header

the header name

String value

the header value

Returns
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 RequestFinishedInfo.Listener, see getAnnotations.

Parameters
Object annotation

an object to pass on to the RequestFinishedInfo.Listener with a RequestFinishedInfo.

Returns
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 UNBIND_NETWORK_HANDLE to unbind.

Returns
BidirectionalStream.Builder

the builder to facilitate chaining.

build

public abstract BidirectionalStream build()

Creates a BidirectionalStream using configuration from this Builder. The returned BidirectionalStream can then be started by calling start.

Returns
BidirectionalStream

constructed BidirectionalStream using configuration from this Builder

delayRequestHeadersUntilFirstFlush

public abstract BidirectionalStream.Builder delayRequestHeadersUntilFirstFlush(
    boolean delayRequestHeadersUntilFirstFlush
)

Delays sending request headers until 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
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
String method

the method to use for request. Default is 'POST'

Returns
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 STREAM_PRIORITY_* values. The stream is given STREAM_PRIORITY_MEDIUM priority if this method is not called.

Parameters
int priority

priority of the stream which should be one of the STREAM_PRIORITY_* values.

Returns
BidirectionalStream.Builder

the builder to facilitate chaining.

setTrafficStatsTag

public BidirectionalStream.Builder setTrafficStatsTag(int tag)

Sets android.net.TrafficStats tag to use when accounting socket traffic caused by this request. See android.net.TrafficStats 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 android.app.DownloadManager when performing traffic on behalf of an application.

Returns
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 android.net.TrafficStats 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
BidirectionalStream.Builder

the builder to facilitate chaining.