Package com.castlabs.sdk.okhttp

## 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)` |
    `OkHttpDataSource​(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, NetworkConfiguration networkConfiguration)` |
    `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)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addTransferListener​(com.google.android.exoplayer2.upstream.TransferListener listener)` |
    `void` | `clearAllRequestProperties()` |
    `void` | `clearRequestProperty​(String name)` |
    `void` | `close()` |
    `int` | `getResponseCode()` |
    `Map<String,​List<String>>` | `getResponseHeaders()` |
    `Uri` | `getUri()` |
    `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` | `setRequestProperty​(String name, String value)` |

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OkHttpDataSource

          public OkHttpDataSource​(okhttp3.Call.Factory callFactory,
                                  String userAgent,
                                  com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate)

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

    - #### 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)

      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

    - #### 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)

      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

  - ### Method Detail

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