BidirectionalStream.Callback

abstract class BidirectionalStream.Callback


Callback class used to receive callbacks from a BidirectionalStream.

Summary

Public constructors

Public functions

Unit

Invoked if the stream was canceled via cancel.

abstract Unit
onFailed(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    error: CronetException!
)

Invoked if the stream failed for any reason after start.

abstract Unit
onReadCompleted(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    buffer: ByteBuffer!,
    endOfStream: Boolean
)

Invoked when data is read into the buffer passed to read().

abstract Unit

Invoked when initial response headers are received.

Unit
onResponseTrailersReceived(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    trailers: UrlResponseInfo.HeaderBlock!
)

Invoked when trailers are received before closing the stream.

abstract Unit

Invoked when the stream is ready for reading and writing.

abstract Unit

Invoked when there is no data to be read or written and the stream is closed successfully remotely and locally.

abstract Unit
onWriteCompleted(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    buffer: ByteBuffer!,
    endOfStream: Boolean
)

Invoked when the entire ByteBuffer passed to write() is sent.

Public constructors

Callback

Callback()

Public functions

onCanceled

fun onCanceled(stream: BidirectionalStream!, info: UrlResponseInfo!): Unit

Invoked if the stream was canceled via cancel. Once invoked, no further BidirectionalStream.Callback methods will be invoked. Default implementation takes no action.

Parameters
stream: BidirectionalStream!

the stream that was canceled

info: UrlResponseInfo!

the response information. May be null if no response was received.

onFailed

abstract fun onFailed(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    error: CronetException!
): Unit

Invoked if the stream failed for any reason after start. HTTP/2 error codes are mapped to getCronetInternalErrorCode codes. Once invoked, no further BidirectionalStream.Callback methods will be invoked.

Parameters
stream: BidirectionalStream!

the stream which has failed

info: UrlResponseInfo!

the response information. May be null if no response was received.

error: CronetException!

information about the failure

onReadCompleted

abstract fun onReadCompleted(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    buffer: ByteBuffer!,
    endOfStream: Boolean
): Unit

Invoked when data is read into the buffer passed to read(). Only part of the buffer may be populated. To continue reading, call read(). It may be invoked after onResponseTrailersReceived(), if there was pending read data before trailers were received.

Parameters
stream: BidirectionalStream!

the stream on which the read completed

info: UrlResponseInfo!

the response information

buffer: ByteBuffer!

the buffer that was passed to read(), now containing the received data. The buffer's limit is not changed. The buffer's position is set to the end of the received data. If position is not updated, it means the remote side has signaled that it will send no more data.

endOfStream: Boolean

if true, this is the last read data, remote will not send more data, and the read side is closed.

onResponseHeadersReceived

abstract fun onResponseHeadersReceived(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!
): Unit

Invoked when initial response headers are received. Headers are available from info.getAllHeaders(). Consumer may call read() to start reading. Consumer may call write() to start writing or close the stream.

Parameters
stream: BidirectionalStream!

the stream on which response headers were received.

info: UrlResponseInfo!

the response information.

onResponseTrailersReceived

fun onResponseTrailersReceived(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    trailers: UrlResponseInfo.HeaderBlock!
): Unit

Invoked when trailers are received before closing the stream. Only invoked when server sends trailers, which it may not. May be invoked while there is read data remaining in local buffer. Default implementation takes no action.

Parameters
stream: BidirectionalStream!

the stream on which response trailers were received

info: UrlResponseInfo!

the response information

trailers: UrlResponseInfo.HeaderBlock!

the trailers received

onStreamReady

abstract fun onStreamReady(stream: BidirectionalStream!): Unit

Invoked when the stream is ready for reading and writing. Consumer may call read() to start reading data. Consumer may call write() to start writing data.

Parameters
stream: BidirectionalStream!

the stream that is ready.

onSucceeded

abstract fun onSucceeded(stream: BidirectionalStream!, info: UrlResponseInfo!): Unit

Invoked when there is no data to be read or written and the stream is closed successfully remotely and locally. Once invoked, no further BidirectionalStream.Callback methods will be invoked.

Parameters
stream: BidirectionalStream!

the stream which is closed successfully

info: UrlResponseInfo!

the response information

onWriteCompleted

abstract fun onWriteCompleted(
    stream: BidirectionalStream!,
    info: UrlResponseInfo!,
    buffer: ByteBuffer!,
    endOfStream: Boolean
): Unit

Invoked when the entire ByteBuffer passed to write() is sent. The buffer's position is updated to be the same as the buffer's limit. The buffer's limit is not changed. To continue writing, call write().

Parameters
stream: BidirectionalStream!

the stream on which the write completed

info: UrlResponseInfo!

the response information

buffer: ByteBuffer!

the buffer that was passed to write(). The buffer's position is set to the buffer's limit. The buffer's limit is not changed.

endOfStream: Boolean

the endOfStream flag that was passed to the corresponding write(). If true, the write side is closed.