Added in API level 34
Also in S Extensions 7

BidirectionalStream.Callback


public static interface BidirectionalStream.Callback

android.net.http.BidirectionalStream.Callback


Callback interface used to receive callbacks from a BidirectionalStream.

Summary

Public methods

abstract void onCanceled(BidirectionalStream stream, UrlResponseInfo info)

Invoked if the stream was canceled via BidirectionalStream.cancel.

abstract void onFailed(BidirectionalStream stream, UrlResponseInfo info, HttpException error)

Invoked if the stream failed for any reason after BidirectionalStream.start.

abstract void onReadCompleted(BidirectionalStream stream, UrlResponseInfo info, ByteBuffer buffer, boolean endOfStream)

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

abstract void onResponseHeadersReceived(BidirectionalStream stream, UrlResponseInfo info)

Invoked when initial response headers are received.

abstract void onResponseTrailersReceived(BidirectionalStream stream, UrlResponseInfo info, HeaderBlock trailers)

Invoked when trailers are received before closing the stream.

abstract void onStreamReady(BidirectionalStream stream)

Invoked when the stream is ready for reading and writing.

abstract void onSucceeded(BidirectionalStream stream, UrlResponseInfo info)

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

abstract void onWriteCompleted(BidirectionalStream stream, UrlResponseInfo info, ByteBuffer buffer, boolean endOfStream)

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

Public methods

onCanceled

Added in API level 34
Also in S Extensions 7
public abstract void onCanceled (BidirectionalStream stream, 
                UrlResponseInfo info)

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

Parameters
stream BidirectionalStream: the stream that was canceled. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information. May be null if no response was received.

onFailed

Added in API level 34
Also in S Extensions 7
public abstract void onFailed (BidirectionalStream stream, 
                UrlResponseInfo info, 
                HttpException error)

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

Parameters
stream BidirectionalStream: the stream which has failed. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information. May be null if no response was received.

error HttpException: information about the failure This value cannot be null.

onReadCompleted

Added in API level 34
Also in S Extensions 7
public abstract void onReadCompleted (BidirectionalStream stream, 
                UrlResponseInfo info, 
                ByteBuffer buffer, 
                boolean endOfStream)

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. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information This value cannot be null.

buffer ByteBuffer: the buffer that was passed to read(), now 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. This value cannot be null.

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

onResponseHeadersReceived

Added in API level 34
Also in S Extensions 7
public abstract void onResponseHeadersReceived (BidirectionalStream stream, 
                UrlResponseInfo info)

Invoked when initial response headers are received. Headers are available from info.getHeaders(). 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. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information. This value cannot be null.

onResponseTrailersReceived

Added in API level 34
Also in S Extensions 7
public abstract void onResponseTrailersReceived (BidirectionalStream stream, 
                UrlResponseInfo info, 
                HeaderBlock trailers)

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. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information This value cannot be null.

trailers HeaderBlock: the trailers received This value cannot be null.

onStreamReady

Added in API level 34
Also in S Extensions 7
public abstract void onStreamReady (BidirectionalStream stream)

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. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

onSucceeded

Added in API level 34
Also in S Extensions 7
public abstract void onSucceeded (BidirectionalStream stream, 
                UrlResponseInfo info)

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. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information This value cannot be null.

onWriteCompleted

Added in API level 34
Also in S Extensions 7
public abstract void onWriteCompleted (BidirectionalStream stream, 
                UrlResponseInfo info, 
                ByteBuffer buffer, 
                boolean endOfStream)

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. This is not guaranteed to be the same object as the one received by other callbacks, nor is it guaranteed to be the one returned by BidirectionalStream.Builder.build. However, method calls on this object will have the same effects as calls on the original BidirectionalStream. This value cannot be null.

info UrlResponseInfo: the response information This value cannot be null.

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. This value cannot be null.

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