InMemoryTransformCronetCallback

abstract class InMemoryTransformCronetCallback<T> : ImplicitFlowControlCallback

Known direct subclasses
ByteArrayCronetCallback

A specialization of InMemoryTransformCronetCallback which returns the body bytes verbatim without any interpretation.

JsonCronetCallback

A specialization of InMemoryTransformCronetCallback that interprets the response body as JSON.

StringCronetCallback

A specialization of InMemoryTransformCronetCallback that interprets the response body as a string.


An abstract Cronet callback that reads the entire body to memory and optionally deserializes the body before passing it back to the issuer of the HTTP request.

The requester can subscribe for updates about the request by adding completion mListeners on the callback. When the request reaches a terminal state, the mListeners are informed in order of addition.

Parameters
<T>

the response body type

Summary

Public constructors

Public functions

ImplicitFlowControlCallback!

Adds a completion listener.

Protected functions

Unit

Invoked whenever part of the response body has been read.

Unit

Invoked if request was canceled via cancel.

Unit
onFailed(info: UrlResponseInfo?, exception: CronetException!)

Invoked if request failed for any reason after start.

Unit

Invoked when the final set of headers, after all redirects, is received.

Unit

Invoked when request is completed successfully.

abstract T!

Transforms (deserializes) the plain full body into a user-defined object.

Inherited functions

From org.chromium.net.apihelpers.ImplicitFlowControlCallback
Unit
onCanceled(request: UrlRequest!, info: UrlResponseInfo!)

Invoked if request was canceled via cancel.

Unit
onFailed(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    error: CronetException!
)

Invoked if request failed for any reason after start.

Unit
onReadCompleted(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    byteBuffer: ByteBuffer!
)

Invoked whenever part of the response body has been read.

Unit
onRedirectReceived(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    newLocationUrl: String!
)

Invoked whenever a redirect is encountered.

Unit

Invoked when the final set of headers, after all redirects, is received.

Unit
onSucceeded(request: UrlRequest!, info: UrlResponseInfo!)

Invoked when request is completed successfully.

abstract Boolean
shouldFollowRedirect(info: UrlResponseInfo!, newLocationUrl: String!)

Invoked whenever a redirect is encountered.

From org.chromium.net.UrlRequest.Callback
abstract Unit
onFailed(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    error: CronetException!
)

Invoked if request failed for any reason after start.

abstract Unit
onReadCompleted(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    byteBuffer: ByteBuffer!
)

Invoked whenever part of the response body has been read.

abstract Unit
onRedirectReceived(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    newLocationUrl: String!
)

Invoked whenever a redirect is encountered.

Public constructors

InMemoryTransformCronetCallback

InMemoryTransformCronetCallback()

Public functions

addCompletionListener

fun addCompletionListener(listener: CronetRequestCompletionListener<T!>!): ImplicitFlowControlCallback!

Adds a completion listener. All listeners are informed when the request reaches a terminal state, in order of addition. If a listener is added multiple times, it will only be called once according to the first time it was added.

Protected functions

onBodyChunkRead

protected fun onBodyChunkRead(info: UrlResponseInfo!, bodyChunk: ByteBuffer!): Unit

Invoked whenever part of the response body has been read. Only part of the buffer may be populated, even if the entire response body has not yet been consumed. The buffer is ready for reading. Buffers are reused internally so the implementing class shouldn't store the buffer or use it anywhere else than in the implementation of this method.

Parameters
info: UrlResponseInfo!

Response information.

bodyChunk: ByteBuffer!

The buffer that contains the received data, flipped for reading.

Throws
java.lang.Exception

if an error occurs while processing a read completion. onFailed will be called with the thrown exception set as the cause of the CallbackException.

onCanceled

protected fun onCanceled(info: UrlResponseInfo?): Unit

Invoked if request was canceled via cancel. Once invoked, no other UrlRequest.Callback methods will be invoked.

Parameters
info: UrlResponseInfo?

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

onFailed

protected fun onFailed(info: UrlResponseInfo?, exception: CronetException!): Unit

Invoked if request failed for any reason after start. Once invoked, no other UrlRequest.Callback methods will be invoked. error provides information about the failure.

Parameters
info: UrlResponseInfo?

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

exception: CronetException!

information about error.

onResponseStarted

protected fun onResponseStarted(info: UrlResponseInfo!): Unit

Invoked when the final set of headers, after all redirects, is received. Will only be invoked once for each request. It's guaranteed that Cronet doesn't start reading the body until this method returns.

Parameters
info: UrlResponseInfo!

Response information.

Throws
java.lang.Exception

if an error occurs while processing response start. onFailed will be called with the thrown exception set as the cause of the CallbackException.

onSucceeded

protected fun onSucceeded(info: UrlResponseInfo!): Unit

Invoked when request is completed successfully. Once invoked, no other UrlRequest.Callback methods will be invoked.

Parameters
info: UrlResponseInfo!

Response information.

transformBodyBytes

protected abstract fun transformBodyBytes(info: UrlResponseInfo!, bodyBytes: ByteArray!): T!

Transforms (deserializes) the plain full body into a user-defined object.

It is assumed that the implementing classes handle edge cases (such as empty and malformed bodies) appropriately. Cronet doesn't inspects the objects and passes them (or any exceptions) along to the issuer of the request.