BidirectionalStream


public abstract class BidirectionalStream
extends Object

java.lang.Object
   ↳ android.net.http.BidirectionalStream


Class for bidirectional sending and receiving of data over HTTP/2 or QUIC connections. Created by Builder. Note: There are ordering restrictions on methods of BidirectionalStream; please see individual methods for description of restrictions.

Summary

Nested classes

class BidirectionalStream.Builder

Builder for BidirectionalStreams. 

interface BidirectionalStream.Callback

Callback interface used to receive callbacks from a BidirectionalStream

Constants

int STREAM_PRIORITY_HIGHEST

Highest stream priority.

int STREAM_PRIORITY_IDLE

Lowest stream priority.

int STREAM_PRIORITY_LOW

Low stream priority.

int STREAM_PRIORITY_LOWEST

Very low stream priority.

int STREAM_PRIORITY_MEDIUM

Medium stream priority.

Public constructors

BidirectionalStream()

Public methods

abstract void cancel()

Cancels the stream.

abstract void flush()

Flushes pending writes.

abstract HeaderBlock getHeaders()

See Builder#addHeader(String, String)

abstract String getHttpMethod()

See BidirectionalStream.Builder#setHttpMethod(String).

abstract int getPriority()

See Builder#setPriority(int)

abstract int getTrafficStatsTag()

See BidirectionalStream.Builder#setTrafficStatsTag(int)

abstract int getTrafficStatsUid()

See BidirectionalStream.Builder#setTrafficStatsUid(int)

abstract boolean hasTrafficStatsTag()

See BidirectionalStream.Builder#setTrafficStatsTag(int)

abstract boolean hasTrafficStatsUid()

See BidirectionalStream.Builder#setTrafficStatsUid(int)

abstract boolean isDelayRequestHeadersUntilFirstFlushEnabled()

See Builder#setDelayRequestHeadersUntilFirstFlushEnabled(boolean)

abstract boolean isDone()

Returns true if the stream was successfully started and is now done (succeeded, canceled, or failed).

abstract void read(ByteBuffer buffer)

Reads data from the stream into the provided buffer.

abstract void start()

Starts the stream, all callbacks go to the callback argument passed to BidirectionalStream.Builder's constructor.

abstract void write(ByteBuffer buffer, boolean endOfStream)

Attempts to write data from the provided buffer into the stream.

Inherited methods

Constants

STREAM_PRIORITY_HIGHEST

Added in API level 34
Also in S Extensions 7
public static final int STREAM_PRIORITY_HIGHEST

Highest stream priority. Passed to Builder#setPriority.

Constant Value: 4 (0x00000004)

STREAM_PRIORITY_IDLE

Added in API level 34
Also in S Extensions 7
public static final int STREAM_PRIORITY_IDLE

Lowest stream priority. Passed to Builder#setPriority.

Constant Value: 0 (0x00000000)

STREAM_PRIORITY_LOW

Added in API level 34
Also in S Extensions 7
public static final int STREAM_PRIORITY_LOW

Low stream priority. Passed to Builder#setPriority.

Constant Value: 2 (0x00000002)

STREAM_PRIORITY_LOWEST

Added in API level 34
Also in S Extensions 7
public static final int STREAM_PRIORITY_LOWEST

Very low stream priority. Passed to Builder#setPriority.

Constant Value: 1 (0x00000001)

STREAM_PRIORITY_MEDIUM

Added in API level 34
Also in S Extensions 7
public static final int STREAM_PRIORITY_MEDIUM

Medium stream priority. Passed to Builder#setPriority. This is the default priority given to the stream.

Constant Value: 3 (0x00000003)

Public constructors

BidirectionalStream

Added in API level 34
Also in S Extensions 7
public BidirectionalStream ()

Public methods

cancel

Added in API level 34
Also in S Extensions 7
public abstract void cancel ()

Cancels the stream. Can be called at any time after start(). onCanceled() will be invoked when cancelation is complete and no further callback methods will be invoked. If the stream has completed or has not started, calling cancel() has no effect and onCanceled() will not be invoked. If the Executor passed in during BidirectionalStream construction runs tasks on a single thread, and cancel() is called on that thread, no listener methods (besides onCanceled()) will be invoked after cancel() is called. Otherwise, at most one callback method may be invoked after cancel() has completed.

flush

Added in API level 34
Also in S Extensions 7
public abstract void flush ()

Flushes pending writes. This method should not be invoked before onStreamReady(). For previously delayed write()s, a corresponding onWriteCompleted() will be invoked when the buffer is sent.

getHeaders

Added in API level 34
Also in S Extensions 7
public abstract HeaderBlock getHeaders ()

See Builder#addHeader(String, String)

Returns
HeaderBlock This value cannot be null.

getHttpMethod

Added in API level 34
Also in S Extensions 7
public abstract String getHttpMethod ()

See BidirectionalStream.Builder#setHttpMethod(String).

Returns
String This value cannot be null.

getPriority

Added in API level 34
Also in S Extensions 7
public abstract int getPriority ()

See Builder#setPriority(int)

Returns
int Value is STREAM_PRIORITY_IDLE, STREAM_PRIORITY_LOWEST, STREAM_PRIORITY_LOW, STREAM_PRIORITY_MEDIUM, or STREAM_PRIORITY_HIGHEST

getTrafficStatsTag

Added in API level 34
Also in S Extensions 7
public abstract int getTrafficStatsTag ()

See BidirectionalStream.Builder#setTrafficStatsTag(int)

Returns
int

getTrafficStatsUid

Added in API level 34
Also in S Extensions 7
public abstract int getTrafficStatsUid ()

See BidirectionalStream.Builder#setTrafficStatsUid(int)

Returns
int

hasTrafficStatsTag

Added in API level 34
Also in S Extensions 7
public abstract boolean hasTrafficStatsTag ()

See BidirectionalStream.Builder#setTrafficStatsTag(int)

Returns
boolean

hasTrafficStatsUid

Added in API level 34
Also in S Extensions 7
public abstract boolean hasTrafficStatsUid ()

See BidirectionalStream.Builder#setTrafficStatsUid(int)

Returns
boolean

isDelayRequestHeadersUntilFirstFlushEnabled

Added in API level 34
Also in S Extensions 7
public abstract boolean isDelayRequestHeadersUntilFirstFlushEnabled ()

See Builder#setDelayRequestHeadersUntilFirstFlushEnabled(boolean)

Returns
boolean

isDone

Added in API level 34
Also in S Extensions 7
public abstract boolean isDone ()

Returns true if the stream was successfully started and is now done (succeeded, canceled, or failed).

Returns
boolean true if the stream was successfully started and is now done (completed, canceled, or failed), otherwise returns false to indicate stream is not yet started or is in progress.

read

Added in API level 34
Also in S Extensions 7
public abstract void read (ByteBuffer buffer)

Reads data from the stream into the provided buffer. Can only be called at most once in response to each invocation of the onStreamReady()/ onResponseHeadersReceived() and onReadCompleted() methods of the Callback. Each call will result in an invocation of one of the Callback's onReadCompleted() method if data is read, or its onFailed() method if there's an error. An attempt to read data into buffer starting at buffer.position() is begun. At most buffer.remaining() bytes are read. buffer.position() is updated upon invocation of onReadCompleted() to indicate how much data was read.

Parameters
buffer ByteBuffer: the ByteBuffer to read data into. Must be a direct ByteBuffer. The embedder must not read or modify buffer's position, limit, or data between its position and limit until onReadCompleted(), onCanceled(), or onFailed() are invoked. This value cannot be null.

start

Added in API level 34
Also in S Extensions 7
public abstract void start ()

Starts the stream, all callbacks go to the callback argument passed to BidirectionalStream.Builder's constructor. Should only be called once.

write

Added in API level 34
Also in S Extensions 7
public abstract void write (ByteBuffer buffer, 
                boolean endOfStream)

Attempts to write data from the provided buffer into the stream. If auto flush is disabled, data will be sent only after flush() is called. Each call will result in an invocation of one of the Callback's onWriteCompleted() method if data is sent, or its onFailed() method if there's an error. An attempt to write data from buffer starting at buffer.position() is begun. buffer.remaining() bytes will be written. onWriteCompleted() will be invoked only when the full ByteBuffer is written.

Parameters
buffer ByteBuffer: the ByteBuffer to write data from. Must be a direct ByteBuffer. The embedder must not read or modify buffer's position, limit, or data between its position and limit until onWriteCompleted(), onCanceled(), or onFailed() are invoked. Can be empty when endOfStream is true. This value cannot be null.

endOfStream boolean: if true, then buffer is the last buffer to be written, and once written, stream is closed from the client side, resulting in half-closed stream or a fully closed stream if the remote side has already closed.