CronetDataSource.Factory


class CronetDataSource.Factory : HttpDataSource.Factory


DataSource.Factory for CronetDataSource instances.

Summary

Public constructors

Factory(cronetEngine: CronetEngine!, executor: Executor!)

Creates an instance.

@UnstableApi
Factory(cronetEngineWrapper: CronetEngineWrapper!, executor: Executor!)

This function is deprecated.

Use Factory with an instantiated , or DefaultHttpDataSource for cases where getCronetEngine would have returned null.

Public functions

HttpDataSource!

Creates a DataSource instance.

CronetDataSource.Factory!

Sets the connect timeout, in milliseconds.

CronetDataSource.Factory!

Sets a content type Predicate.

CronetDataSource.Factory!

Sets the default request headers for HttpDataSource instances created by the factory.

CronetDataSource.Factory!

This function is deprecated.

Do not use CronetDataSource or its factory in cases where a suitable CronetEngine is not available.

CronetDataSource.Factory!

Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

CronetDataSource.Factory!

Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.

CronetDataSource.Factory!

Sets the read buffer size, in bytes.

CronetDataSource.Factory!

Sets the read timeout, in milliseconds.

CronetDataSource.Factory!

Sets the priority of requests made by CronetDataSource instances created by this factory.

CronetDataSource.Factory!

Sets whether the connect timeout is reset when a redirect occurs.

CronetDataSource.Factory!

Sets the TransferListener that will be used.

CronetDataSource.Factory!

Sets the user agent that will be used.

Inherited functions

From androidx.media3.datasource.DataSource.Factory
abstract DataSource!

Creates a DataSource instance.

Public constructors

Factory

Factory(cronetEngine: CronetEngine!, executor: Executor!)

Creates an instance.

Parameters
cronetEngine: CronetEngine!

A CronetEngine to make the requests. This should not be a fallback instance obtained from JavaCronetProvider. It's more efficient to use DefaultHttpDataSource instead in this case.

executor: Executor!

The java.util.concurrent.Executor that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.

Factory

@UnstableApi
Factory(cronetEngineWrapper: CronetEngineWrapper!, executor: Executor!)

Creates an instance.

Parameters
cronetEngineWrapper: CronetEngineWrapper!

A CronetEngineWrapper.

executor: Executor!

The java.util.concurrent.Executor that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.

Public functions

createDataSource

@UnstableApi
fun createDataSource(): HttpDataSource!

Creates a DataSource instance.

setConnectionTimeoutMs

@CanIgnoreReturnValue
@UnstableApi
fun setConnectionTimeoutMs(connectTimeoutMs: Int): CronetDataSource.Factory!

Sets the connect timeout, in milliseconds.

The default is DEFAULT_CONNECT_TIMEOUT_MILLIS.

Parameters
connectTimeoutMs: Int

The connect timeout, in milliseconds, that will be used.

Returns
CronetDataSource.Factory!

This factory.

setContentTypePredicate

@CanIgnoreReturnValue
@UnstableApi
fun setContentTypePredicate(contentTypePredicate: Predicate<String!>?): CronetDataSource.Factory!

Sets a content type Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from open.

The default is null.

Parameters
contentTypePredicate: Predicate<String!>?

The content type Predicate, or null to clear a predicate that was previously set.

Returns
CronetDataSource.Factory!

This factory.

setDefaultRequestProperties

@CanIgnoreReturnValue
@UnstableApi
fun setDefaultRequestProperties(
    defaultRequestProperties: (Mutable)Map<String!, String!>!
): CronetDataSource.Factory!

Sets the default request headers for HttpDataSource instances created by the factory.

The new request properties will be used for future requests made by HttpDataSources created by the factory, including instances that have already been created. Modifying the defaultRequestProperties map after a call to this method will have no effect, and so it's necessary to call this method again each time the request properties need to be updated.

Parameters
defaultRequestProperties: (Mutable)Map<String!, String!>!

The default request properties.

Returns
CronetDataSource.Factory!

This factory.

setFallbackFactory

@CanIgnoreReturnValue
@UnstableApi
fun setFallbackFactory(fallbackFactory: HttpDataSource.Factory?): CronetDataSource.Factory!

Sets the fallback HttpDataSource.Factory that is used as a fallback if the fails to provide a CronetEngine.

By default a DefaultHttpDataSource is used as fallback factory.

Parameters
fallbackFactory: HttpDataSource.Factory?

The fallback factory that will be used.

Returns
CronetDataSource.Factory!

This factory.

setHandleSetCookieRequests

@CanIgnoreReturnValue
@UnstableApi
fun setHandleSetCookieRequests(handleSetCookieRequests: Boolean): CronetDataSource.Factory!

Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

The default is false.

Parameters
handleSetCookieRequests: Boolean

Whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

Returns
CronetDataSource.Factory!

This factory.

setKeepPostFor302Redirects

@CanIgnoreReturnValue
@UnstableApi
fun setKeepPostFor302Redirects(keepPostFor302Redirects: Boolean): CronetDataSource.Factory!

Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.

setReadBufferSize

@CanIgnoreReturnValue
@UnstableApi
fun setReadBufferSize(readBufferSize: Int): CronetDataSource.Factory!

Sets the read buffer size, in bytes.

Parameters
readBufferSize: Int

The read buffer size, in bytes.

Returns
CronetDataSource.Factory!

This factory.

setReadTimeoutMs

@CanIgnoreReturnValue
@UnstableApi
fun setReadTimeoutMs(readTimeoutMs: Int): CronetDataSource.Factory!

Sets the read timeout, in milliseconds.

The default is DEFAULT_READ_TIMEOUT_MILLIS.

Parameters
readTimeoutMs: Int

The connect timeout, in milliseconds, that will be used.

Returns
CronetDataSource.Factory!

This factory.

setRequestPriority

@CanIgnoreReturnValue
@UnstableApi
fun setRequestPriority(requestPriority: Int): CronetDataSource.Factory!

Sets the priority of requests made by CronetDataSource instances created by this factory.

The default is REQUEST_PRIORITY_MEDIUM.

Parameters
requestPriority: Int

The request priority, which should be one of Cronet's UrlRequest.Builder#REQUEST_PRIORITY_* constants.

Returns
CronetDataSource.Factory!

This factory.

setResetTimeoutOnRedirects

@CanIgnoreReturnValue
@UnstableApi
fun setResetTimeoutOnRedirects(resetTimeoutOnRedirects: Boolean): CronetDataSource.Factory!

Sets whether the connect timeout is reset when a redirect occurs.

The default is false.

Parameters
resetTimeoutOnRedirects: Boolean

Whether the connect timeout is reset when a redirect occurs.

Returns
CronetDataSource.Factory!

This factory.

setTransferListener

@CanIgnoreReturnValue
@UnstableApi
fun setTransferListener(transferListener: TransferListener?): CronetDataSource.Factory!

Sets the TransferListener that will be used.

The default is null.

See addTransferListener.

Parameters
transferListener: TransferListener?

The listener that will be used.

Returns
CronetDataSource.Factory!

This factory.

setUserAgent

@CanIgnoreReturnValue
@UnstableApi
fun setUserAgent(userAgent: String?): CronetDataSource.Factory!

Sets the user agent that will be used.

The default is null, which causes the default user agent of the underlying to be used.

Parameters
userAgent: String?

The user agent that will be used, or null to use the default user agent of the underlying CronetEngine.

Returns
CronetDataSource.Factory!

This factory.