Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

# BidirectionalStream.Callback

*** ** * ** ***


`
public
static


interface
BidirectionalStream.Callback
`


`


`

|---|
| android.net.http.BidirectionalStream.Callback |

<br />

*** ** * ** ***

Callback interface used to receive callbacks from a `https://developer.android.com/reference/android/net/http/BidirectionalStream`.

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onCanceled(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info) ` Invoked if the stream was canceled via `https://developer.android.com/reference/android/net/http/BidirectionalStream#cancel()`. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onFailed(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo,%20android.net.http.HttpException)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info, https://developer.android.com/reference/android/net/http/HttpException error) ` Invoked if the stream failed for any reason after `https://developer.android.com/reference/android/net/http/BidirectionalStream#start()`. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onReadCompleted(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo,%20java.nio.ByteBuffer,%20boolean)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info, https://developer.android.com/reference/java/nio/ByteBuffer buffer, boolean endOfStream) ` Invoked when data is read into the buffer passed to `https://developer.android.com/reference/android/net/http/BidirectionalStream#read(java.nio.ByteBuffer)`. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onResponseHeadersReceived(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info) ` Invoked when initial response headers are received. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onResponseTrailersReceived(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo,%20android.net.http.HeaderBlock)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info, https://developer.android.com/reference/android/net/http/HeaderBlock trailers) ` Invoked when trailers are received before closing the stream. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onStreamReady(android.net.http.BidirectionalStream)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream) ` Invoked when the stream is ready for reading and writing. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onSucceeded(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info) ` Invoked when there is no data to be read or written and the stream is closed successfully remotely and locally. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback#onWriteCompleted(android.net.http.BidirectionalStream,%20android.net.http.UrlResponseInfo,%20java.nio.ByteBuffer,%20boolean)(https://developer.android.com/reference/android/net/http/BidirectionalStream stream, https://developer.android.com/reference/android/net/http/UrlResponseInfo info, https://developer.android.com/reference/java/nio/ByteBuffer buffer, boolean endOfStream) ` Invoked when the entire ByteBuffer passed to `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)` is sent. |

## Public methods

### onCanceled

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract void onCanceled (BidirectionalStream stream, 
                UrlResponseInfo info)
```

Invoked if the stream was canceled via `https://developer.android.com/reference/android/net/http/BidirectionalStream#cancel()`. Once invoked,
no further `https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback` methods will be invoked. Default
implementation takes no action.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. May be `null` if no response was received. <br /> |

### onFailed

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

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

Invoked if the stream failed for any reason after `https://developer.android.com/reference/android/net/http/BidirectionalStream#start()`.
[HTTP/2 error codes](https://tools.ietf.org/html/rfc7540#section-7) are
mapped to `https://developer.android.com/reference/android/net/http/NetworkException#getErrorCode()` codes. Once invoked,
no further `https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback` methods will be invoked.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. May be `null` if no response was received. <br /> |
| `error` | `HttpException`: information about the failure. This value cannot be `null`. <br /> |

### onReadCompleted

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

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

Invoked when data is read into the buffer passed to `https://developer.android.com/reference/android/net/http/BidirectionalStream#read(java.nio.ByteBuffer)`. Only part of the buffer may be populated. To continue reading, call `https://developer.android.com/reference/android/net/http/BidirectionalStream#read(java.nio.ByteBuffer)`. It may be invoked after `onResponseTrailersReceived()`, if there was pending read data before trailers were
received.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. This value cannot be `null`. <br /> |
| `buffer` | `ByteBuffer`: the buffer that was passed to `https://developer.android.com/reference/android/net/http/BidirectionalStream#read(java.nio.ByteBuffer)`, 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`. <br /> |
| `endOfStream` | `boolean`: if true, this is the last read data, remote will not send more data, and the read side is closed. <br /> |

### onResponseHeadersReceived

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract void onResponseHeadersReceived (BidirectionalStream stream, 
                UrlResponseInfo info)
```

Invoked when initial response headers are received. Headers are available from `info.``https://developer.android.com/reference/android/net/http/UrlResponseInfo#getHeaders()`. Consumer may call `https://developer.android.com/reference/android/net/http/BidirectionalStream#read(java.nio.ByteBuffer)` to start reading. Consumer may call `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)` to start writing or close the stream.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. This value cannot be `null`. <br /> |

### onResponseTrailersReceived

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
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.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. This value cannot be `null`. <br /> |
| `trailers` | `HeaderBlock`: the trailers received. This value cannot be `null`. <br /> |

### onStreamReady

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract void onStreamReady (BidirectionalStream stream)
```

Invoked when the stream is ready for reading and writing. Consumer may call `https://developer.android.com/reference/android/net/http/BidirectionalStream#read(java.nio.ByteBuffer)` to start reading data. Consumer may call `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)` to start writing data.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |

### onSucceeded

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback`
methods will be invoked.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. This value cannot be `null`. <br /> |

### onWriteCompleted

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

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

Invoked when the entire ByteBuffer passed to `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)` 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)`.

<br />

| 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 `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder#build()`.** However, method calls on this object will have the same effects as calls on the original `https://developer.android.com/reference/android/net/http/BidirectionalStream`. This value cannot be `null`. <br /> |
| `info` | `UrlResponseInfo`: the response information. This value cannot be `null`. <br /> |
| `buffer` | `ByteBuffer`: the buffer that was passed to `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)`. The buffer's position is set to the buffer's limit. The buffer's limit is not changed. This value cannot be `null`. <br /> |
| `endOfStream` | `boolean`: the endOfStream flag that was passed to the corresponding `https://developer.android.com/reference/android/net/http/BidirectionalStream#write(java.nio.ByteBuffer,%20boolean)`. If true, the write side is closed. <br /> |