Package com.google.android.exoplayer2.upstream

## Class DataSpec.Builder

- java.lang.Object
- - com.google.android.exoplayer2.upstream.DataSpec.Builder

- Enclosing class:
    DataSpec

      public static final class DataSpec.Builder
      extends Object

  Builds `DataSpec` instances.

  Use DataSpec#buildUpon() to obtain a builder representing an existing `DataSpec`.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Builder()` | Creates a new instance with default values.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DataSpec` | `build()` | Builds a `DataSpec` with the builder's current values.
    `DataSpec.Builder` | `setCustomData​(Object customData)` | Sets the `DataSpec.customData`.
    `DataSpec.Builder` | `setFlags​(@com.google.android.exoplayer2.upstream.DataSpec.Flags int flags)` | Sets the `DataSpec.flags`.
    `DataSpec.Builder` | `setHttpBody​(byte[] httpBody)` | Sets `DataSpec.httpBody`.
    `DataSpec.Builder` | `setHttpMethod​(@com.google.android.exoplayer2.upstream.DataSpec.HttpMethod int httpMethod)` | Sets `DataSpec.httpMethod`.
    `DataSpec.Builder` | `setHttpRequestHeaders​(Map<String,​String> httpRequestHeaders)` | Sets the `DataSpec.httpRequestHeaders`.
    `DataSpec.Builder` | `setKey​(String key)` | Sets the `DataSpec.key`.
    `DataSpec.Builder` | `setLength​(long length)` | Sets the `DataSpec.length`.
    `DataSpec.Builder` | `setPosition​(long position)` | Sets the `DataSpec.position`.
    `DataSpec.Builder` | `setUri​(Uri uri)` | Sets `DataSpec.uri`.
    `DataSpec.Builder` | `setUri​(String uriString)` | Sets `DataSpec.uri`.
    `DataSpec.Builder` | `setUriPositionOffset​(long uriPositionOffset)` | Sets the `DataSpec.uriPositionOffset`.

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

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

- - ### Constructor Detail

    - #### Builder

          public Builder()

      Creates a new instance with default values.

  - ### Method Detail

    - #### setUri

          @CanIgnoreReturnValue
          public DataSpec.Builder setUri​(String uriString)

      Sets `DataSpec.uri`.
      Parameters:
        `uriString` - The `DataSpec.uri`.
      Returns:
        The builder.

    - #### setUri

          @CanIgnoreReturnValue
          public DataSpec.Builder setUri​(Uri uri)

      Sets `DataSpec.uri`.
      Parameters:
        `uri` - The `DataSpec.uri`.
      Returns:
        The builder.

    - #### setUriPositionOffset

          @CanIgnoreReturnValue
          public DataSpec.Builder setUriPositionOffset​(long uriPositionOffset)

      Sets the `DataSpec.uriPositionOffset`. The default value is 0.
      Parameters:
        `uriPositionOffset` - The `DataSpec.uriPositionOffset`.
      Returns:
        The builder.

    - #### setHttpMethod

          @CanIgnoreReturnValue
          public DataSpec.Builder setHttpMethod​(@com.google.android.exoplayer2.upstream.DataSpec.HttpMethod int httpMethod)

      Sets `DataSpec.httpMethod`. The default value is `DataSpec.HTTP_METHOD_GET`.
      Parameters:
        `httpMethod` - The `DataSpec.httpMethod`.
      Returns:
        The builder.

    - #### setHttpBody

          @CanIgnoreReturnValue
          public DataSpec.Builder setHttpBody​(@Nullable
                                              byte[] httpBody)

      Sets `DataSpec.httpBody`. The default value is `null`.
      Parameters:
        `httpBody` - The `DataSpec.httpBody`.
      Returns:
        The builder.

    - #### setHttpRequestHeaders

          @CanIgnoreReturnValue
          public DataSpec.Builder setHttpRequestHeaders​(Map<String,​String> httpRequestHeaders)

      Sets the `DataSpec.httpRequestHeaders`. The default value is an empty map.

      Note: `Range`, `Accept-Encoding` and `User-Agent` should not be set with this method, since they are set directly by `HttpDataSource` implementations. See `DataSpec.httpRequestHeaders` for more details.

      Parameters:
        `httpRequestHeaders` - The `DataSpec.httpRequestHeaders`.
      Returns:
        The builder.

    - #### setPosition

          @CanIgnoreReturnValue
          public DataSpec.Builder setPosition​(long position)

      Sets the `DataSpec.position`. The default value is 0.
      Parameters:
        `position` - The `DataSpec.position`.
      Returns:
        The builder.

    - #### setLength

          @CanIgnoreReturnValue
          public DataSpec.Builder setLength​(long length)

      Sets the `DataSpec.length`. The default value is `C.LENGTH_UNSET`.
      Parameters:
        `length` - The `DataSpec.length`.
      Returns:
        The builder.

    - #### setKey

          @CanIgnoreReturnValue
          public DataSpec.Builder setKey​(@Nullable
                                         String key)

      Sets the `DataSpec.key`. The default value is `null`.
      Parameters:
        `key` - The `DataSpec.key`.
      Returns:
        The builder.

    - #### setFlags

          @CanIgnoreReturnValue
          public DataSpec.Builder setFlags​(@com.google.android.exoplayer2.upstream.DataSpec.Flags int flags)

      Sets the `DataSpec.flags`. The default value is 0.
      Parameters:
        `flags` - The `DataSpec.flags`.
      Returns:
        The builder.

    - #### setCustomData

          @CanIgnoreReturnValue
          public DataSpec.Builder setCustomData​(@Nullable
                                                Object customData)

      Sets the `DataSpec.customData`. The default value is `null`.
      Parameters:
        `customData` - The `DataSpec.customData`.
      Returns:
        The builder.

    - #### build

          public DataSpec build()

      Builds a `DataSpec` with the builder's current values.
      Returns:
        The build `DataSpec`.
      Throws:
        `IllegalStateException` - If `setUri(java.lang.String)` has not been called.