BidirectionalStream


abstract class BidirectionalStream
kotlin.Any
   ↳ 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
abstract

Builder for BidirectionalStreams.

abstract

Callback interface used to receive callbacks from a BidirectionalStream.

Constants
static Int

Highest stream priority.

static Int

Lowest stream priority.

static Int

Low stream priority.

static Int

Very low stream priority.

static Int

Medium stream priority.

Public constructors

Public methods
abstract Unit

Cancels the stream.

abstract Unit

Flushes pending writes.

abstract HeaderBlock

See Builder.addHeader(String, String)

abstract String

See BidirectionalStream.Builder.setHttpMethod(String).

abstract Int

See Builder.setPriority(int)

abstract Int

See BidirectionalStream.Builder.setTrafficStatsTag(int)

abstract Int

See BidirectionalStream.Builder.setTrafficStatsUid(int)

abstract Boolean

See BidirectionalStream.Builder.setTrafficStatsTag(int)

abstract Boolean

See BidirectionalStream.Builder.setTrafficStatsUid(int)

abstract Boolean

See Builder.setDelayRequestHeadersUntilFirstFlushEnabled(boolean)

abstract Boolean

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

abstract Unit
read(buffer: ByteBuffer)

Reads data from the stream into the provided buffer.

abstract Unit

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

abstract Unit
write(buffer: ByteBuffer, endOfStream: Boolean)

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

Constants

STREAM_PRIORITY_HIGHEST

static val STREAM_PRIORITY_HIGHEST: Int

Highest stream priority. Passed to Builder.setPriority.

Value: 4

STREAM_PRIORITY_IDLE

static val STREAM_PRIORITY_IDLE: Int

Lowest stream priority. Passed to Builder.setPriority.

Value: 0

STREAM_PRIORITY_LOW

static val STREAM_PRIORITY_LOW: Int

Low stream priority. Passed to Builder.setPriority.

Value: 2

STREAM_PRIORITY_LOWEST

static val STREAM_PRIORITY_LOWEST: Int

Very low stream priority. Passed to Builder.setPriority.

Value: 1

STREAM_PRIORITY_MEDIUM

static val STREAM_PRIORITY_MEDIUM: Int

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

Value: 3

Public constructors

BidirectionalStream

BidirectionalStream()

Public methods

cancel

abstract fun cancel(): Unit

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

abstract fun flush(): Unit

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

abstract fun getHeaders(): HeaderBlock

See Builder.addHeader(String, String)

Return
HeaderBlock This value cannot be null.

getHttpMethod

abstract fun getHttpMethod(): String

See BidirectionalStream.Builder.setHttpMethod(String).

Return
String This value cannot be null.

getTrafficStatsTag

abstract fun getTrafficStatsTag(): Int

See BidirectionalStream.Builder.setTrafficStatsTag(int)

getTrafficStatsUid

abstract fun getTrafficStatsUid(): Int

See BidirectionalStream.Builder.setTrafficStatsUid(int)

hasTrafficStatsTag

abstract fun hasTrafficStatsTag(): Boolean

See BidirectionalStream.Builder.setTrafficStatsTag(int)

hasTrafficStatsUid

abstract fun hasTrafficStatsUid(): Boolean

See BidirectionalStream.Builder.setTrafficStatsUid(int)

isDelayRequestHeadersUntilFirstFlushEnabled

abstract fun isDelayRequestHeadersUntilFirstFlushEnabled(): Boolean

See Builder.setDelayRequestHeadersUntilFirstFlushEnabled(boolean)

isDone

abstract fun isDone(): Boolean

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

Return
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

abstract fun read(buffer: ByteBuffer): Unit

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

abstract fun start(): Unit

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

write

abstract fun write(
    buffer: ByteBuffer,
    endOfStream: Boolean
): Unit

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.