BidirectionalStream

abstract class 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 types

Builder for BidirectionalStreams.

Callback class used to receive callbacks from a BidirectionalStream.

Public constructors

Public functions

abstract Unit

Cancels the stream.

abstract Unit

Flushes pending writes.

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)

Adds data to be written to the stream.

Public constructors

BidirectionalStream

BidirectionalStream()

Public functions

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.

isDone

abstract fun isDone(): Boolean

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

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.

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

Adds data to be written to the stream. 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.

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.