Class OkHttpDataSource

java.lang.Object
com.castlabs.sdk.okhttp.OkHttpDataSource
All Implemented Interfaces:
com.google.android.exoplayer2.upstream.DataSource, com.google.android.exoplayer2.upstream.HttpDataSource, okhttp3.Interceptor

public class OkHttpDataSource extends Object implements com.google.android.exoplayer2.upstream.HttpDataSource, okhttp3.Interceptor
An HttpDataSource that delegates to Square's Call.Factory.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.HttpDataSource

    com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory, com.google.android.exoplayer2.upstream.HttpDataSource.Factory, com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException, com.google.android.exoplayer2.upstream.HttpDataSource.InvalidContentTypeException, com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException, com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties

    Nested classes/interfaces inherited from interface okhttp3.Interceptor

    okhttp3.Interceptor.Chain
  • Field Summary

    Fields inherited from interface com.google.android.exoplayer2.upstream.HttpDataSource

    REJECT_PAYWALL_TYPES
  • Constructor Summary

    Constructors
    Constructor
    Description
    OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener)
     
    OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener)
     
    OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, okhttp3.CacheControl cacheControl, com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addTransferListener(com.google.android.exoplayer2.upstream.TransferListener listener)
     
    void
     
    void
     
    void
     
    int
     
     
     
    okhttp3.Response
    intercept(okhttp3.Interceptor.Chain chain)
     
    long
    open(com.google.android.exoplayer2.upstream.DataSpec dataSpec)
     
    int
    read(byte[] buffer, int offset, int readLength)
     
    void
    setRedirectListener(com.google.android.exoplayer2.upstream.HttpRedirectListener listener)
     
    void
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OkHttpDataSource

      public OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener)
      Parameters:
      callFactory - A Call.Factory (typically an OkHttpClient) for use by the source.
      userAgent - The User-Agent string that should be used.
      contentTypePredicate - An optional Predicate. If a content type is rejected by the predicate then a InvalidContentTypeException} is thrown from open(DataSpec).
      clientCreatedListener - A listener to inform about new OkHttpClients
    • OkHttpDataSource

      public OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener)
      Parameters:
      callFactory - A Call.Factory (typically an OkHttpClient) for use by the source.
      userAgent - The User-Agent string that should be used.
      contentTypePredicate - An optional Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).
      listener - An optional listener.
      networkConfiguration - The network configuration
      clientCreatedListener - A listener to inform about new OkHttpClients
    • OkHttpDataSource

      public OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, okhttp3.CacheControl cacheControl, com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener)
      Parameters:
      callFactory - A Call.Factory (typically an OkHttpClient) for use by the source.
      userAgent - The User-Agent string that should be used.
      contentTypePredicate - An optional Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).
      listener - An optional listener.
      cacheControl - An optional CacheControl for setting the Cache-Control header.
      defaultRequestProperties - The optional default HttpDataSource.RequestProperties to be sent to the server as HTTP headers on every request.
      networkConfiguration - The network configuration
      clientCreatedListener - A listener to inform about new OkHttpClients
  • Method Details

    • getUri

      public Uri getUri()
      Specified by:
      getUri in interface com.google.android.exoplayer2.upstream.DataSource
    • addTransferListener

      public void addTransferListener(com.google.android.exoplayer2.upstream.TransferListener listener)
      Specified by:
      addTransferListener in interface com.google.android.exoplayer2.upstream.DataSource
    • getResponseHeaders

      public Map<String,List<String>> getResponseHeaders()
      Specified by:
      getResponseHeaders in interface com.google.android.exoplayer2.upstream.DataSource
      Specified by:
      getResponseHeaders in interface com.google.android.exoplayer2.upstream.HttpDataSource
    • setRedirectListener

      public void setRedirectListener(com.google.android.exoplayer2.upstream.HttpRedirectListener listener)
      Specified by:
      setRedirectListener in interface com.google.android.exoplayer2.upstream.HttpDataSource
    • setRequestProperty

      public void setRequestProperty(String name, String value)
      Specified by:
      setRequestProperty in interface com.google.android.exoplayer2.upstream.HttpDataSource
    • clearRequestProperty

      public void clearRequestProperty(String name)
      Specified by:
      clearRequestProperty in interface com.google.android.exoplayer2.upstream.HttpDataSource
    • clearAllRequestProperties

      public void clearAllRequestProperties()
      Specified by:
      clearAllRequestProperties in interface com.google.android.exoplayer2.upstream.HttpDataSource
    • getResponseCode

      public int getResponseCode()
      Specified by:
      getResponseCode in interface com.google.android.exoplayer2.upstream.DataSource
    • open

      public long open(com.google.android.exoplayer2.upstream.DataSpec dataSpec) throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
      Specified by:
      open in interface com.google.android.exoplayer2.upstream.DataSource
      Specified by:
      open in interface com.google.android.exoplayer2.upstream.HttpDataSource
      Throws:
      com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
    • read

      public int read(byte[] buffer, int offset, int readLength) throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
      Specified by:
      read in interface com.google.android.exoplayer2.upstream.DataSource
      Specified by:
      read in interface com.google.android.exoplayer2.upstream.HttpDataSource
      Throws:
      com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
    • close

      public void close() throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
      Specified by:
      close in interface com.google.android.exoplayer2.upstream.DataSource
      Specified by:
      close in interface com.google.android.exoplayer2.upstream.HttpDataSource
      Throws:
      com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
    • intercept

      public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException
      Specified by:
      intercept in interface okhttp3.Interceptor
      Throws:
      IOException