OkHttpDataSource.Factory

public final class OkHttpDataSource.Factory implements HttpDataSource.Factory


DataSource.Factory for OkHttpDataSource instances.

Summary

Public constructors

Factory(Call.Factory callFactory)

Creates an instance.

Public methods

OkHttpDataSource

Creates a DataSource instance.

OkHttpDataSource.Factory

Sets the CacheControl that will be used.

OkHttpDataSource.Factory

Sets a content type Predicate.

final OkHttpDataSource.Factory

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

OkHttpDataSource.Factory

Sets the TransferListener that will be used.

OkHttpDataSource.Factory

Sets the user agent that will be used.

Public constructors

Factory

public Factory(Call.Factory callFactory)

Creates an instance.

Parameters
Call.Factory callFactory

A Call.Factory (typically an OkHttpClient) for use by the sources created by the factory.

Public methods

createDataSource

@UnstableApi
public OkHttpDataSource createDataSource()

Creates a DataSource instance.

setCacheControl

@CanIgnoreReturnValue
@UnstableApi
public OkHttpDataSource.Factory setCacheControl(@Nullable CacheControl cacheControl)

Sets the CacheControl that will be used.

The default is null.

Parameters
@Nullable CacheControl cacheControl

The cache control that will be used.

Returns
OkHttpDataSource.Factory

This factory.

setContentTypePredicate

@CanIgnoreReturnValue
@UnstableApi
public OkHttpDataSource.Factory setContentTypePredicate(
    @Nullable Predicate<String> contentTypePredicate
)

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
@Nullable Predicate<String> contentTypePredicate

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

Returns
OkHttpDataSource.Factory

This factory.

setDefaultRequestProperties

@CanIgnoreReturnValue
@UnstableApi
public final OkHttpDataSource.Factory setDefaultRequestProperties(
    Map<StringString> defaultRequestProperties
)

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
Map<StringString> defaultRequestProperties

The default request properties.

Returns
OkHttpDataSource.Factory

This factory.

setTransferListener

@CanIgnoreReturnValue
@UnstableApi
public OkHttpDataSource.Factory setTransferListener(@Nullable TransferListener transferListener)

Sets the TransferListener that will be used.

The default is null.

See addTransferListener.

Parameters
@Nullable TransferListener transferListener

The listener that will be used.

Returns
OkHttpDataSource.Factory

This factory.

setUserAgent

@CanIgnoreReturnValue
@UnstableApi
public OkHttpDataSource.Factory setUserAgent(@Nullable String userAgent)

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
@Nullable String userAgent

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

Returns
OkHttpDataSource.Factory

This factory.