Package com.google.android.exoplayer2.offline

## Class DefaultDownloadIndex

- java.lang.Object
- - com.google.android.exoplayer2.offline.DefaultDownloadIndex

- All Implemented Interfaces:
    `DownloadIndex`, `WritableDownloadIndex`

      public final class DefaultDownloadIndex
      extends Object
      implements WritableDownloadIndex

  A `DownloadIndex` that uses SQLite to persist `Downloads`.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultDownloadIndex​(DatabaseProvider databaseProvider)` | Creates an instance that stores the `Downloads` in an SQLite database provided by a `DatabaseProvider`.
    `DefaultDownloadIndex​(DatabaseProvider databaseProvider, String name)` | Creates an instance that stores the `Downloads` in an SQLite database provided by a `DatabaseProvider`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Download` | `getDownload​(String id)` | Returns the `Download` with the given `id`, or null.
    `DownloadCursor` | `getDownloads​(@com.google.android.exoplayer2.offline.Download.State int... states)` | Returns a `DownloadCursor` to `Download`s with the given `states`.
    `void` | `putDownload​(Download download)` | Adds or replaces a `Download`.
    `void` | `removeDownload​(String id)` | Removes the download with the given ID.
    `void` | `setDownloadingStatesToQueued()` | Sets all `Download.STATE_DOWNLOADING` states to `Download.STATE_QUEUED`.
    `void` | `setStatesToRemoving()` | Sets all states to `Download.STATE_REMOVING`.
    `void` | `setStopReason​(int stopReason)` | Sets the stop reason of the downloads in a terminal state (`Download.STATE_COMPLETED`, `Download.STATE_FAILED`).
    `void` | `setStopReason​(String id, int stopReason)` | Sets the stop reason of the download with the given ID in a terminal state (`Download.STATE_COMPLETED`, `Download.STATE_FAILED`).

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

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

- - ### Constructor Detail

    - #### DefaultDownloadIndex

          public DefaultDownloadIndex​(DatabaseProvider databaseProvider)

      Creates an instance that stores the `Downloads` in an SQLite database provided by a `DatabaseProvider`.

      Equivalent to calling `DefaultDownloadIndex(DatabaseProvider, String)` with `name=""`.

      Applications that only have one download index may use this constructor. Applications that have multiple download indices should call `DefaultDownloadIndex(DatabaseProvider, String)` to specify a unique name for each index.

      Parameters:
        `databaseProvider` - Provides the SQLite database in which downloads are persisted.

    - #### DefaultDownloadIndex

          public DefaultDownloadIndex​(DatabaseProvider databaseProvider,
                                      String name)

      Creates an instance that stores the `Downloads` in an SQLite database provided by a `DatabaseProvider`.
      Parameters:
        `databaseProvider` - Provides the SQLite database in which downloads are persisted.
        `name` - The name of the index. This name is incorporated into the names of the SQLite tables in which downloads are persisted.

  - ### Method Detail

    - #### getDownload

          @Nullable
          public Download getDownload​(String id)
                               throws DatabaseIOException

      Description copied from interface: `DownloadIndex`
      Returns the `Download` with the given `id`, or null.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `getDownload` in interface `DownloadIndex`
      Parameters:
        `id` - ID of a `Download`.
      Returns:
        The `Download` with the given `id`, or null if a download state with this id doesn't exist.
      Throws:
        `DatabaseIOException`

    - #### getDownloads

          public DownloadCursor getDownloads​(@State
                                             @com.google.android.exoplayer2.offline.Download.State int... states)
                                      throws DatabaseIOException

      Description copied from interface: `DownloadIndex`
      Returns a `DownloadCursor` to `Download`s with the given `states`.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `getDownloads` in interface `DownloadIndex`
      Parameters:
        `states` - Returns only the `Download`s with this states. If empty, returns all.
      Returns:
        A cursor to `Download`s with the given `states`.
      Throws:
        `DatabaseIOException`

    - #### putDownload

          public void putDownload​(Download download)
                           throws DatabaseIOException

      Description copied from interface: `WritableDownloadIndex`
      Adds or replaces a `Download`.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `putDownload` in interface `WritableDownloadIndex`
      Parameters:
        `download` - The `Download` to be added.
      Throws:
        `DatabaseIOException`

    - #### removeDownload

          public void removeDownload​(String id)
                              throws DatabaseIOException

      Description copied from interface: `WritableDownloadIndex`
      Removes the download with the given ID. Does nothing if a download with the given ID does not exist.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `removeDownload` in interface `WritableDownloadIndex`
      Parameters:
        `id` - The ID of the download to remove.
      Throws:
        `DatabaseIOException`

    - #### setDownloadingStatesToQueued

          public void setDownloadingStatesToQueued()
                                            throws DatabaseIOException

      Description copied from interface: `WritableDownloadIndex`
      Sets all `Download.STATE_DOWNLOADING` states to `Download.STATE_QUEUED`.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `setDownloadingStatesToQueued` in interface `WritableDownloadIndex`
      Throws:
        `DatabaseIOException`

    - #### setStatesToRemoving

          public void setStatesToRemoving()
                                   throws DatabaseIOException

      Description copied from interface: `WritableDownloadIndex`
      Sets all states to `Download.STATE_REMOVING`.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `setStatesToRemoving` in interface `WritableDownloadIndex`
      Throws:
        `DatabaseIOException`

    - #### setStopReason

          public void setStopReason​(int stopReason)
                             throws DatabaseIOException

      Description copied from interface: `WritableDownloadIndex`
      Sets the stop reason of the downloads in a terminal state (`Download.STATE_COMPLETED`, `Download.STATE_FAILED`).

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `setStopReason` in interface `WritableDownloadIndex`
      Parameters:
        `stopReason` - The stop reason.
      Throws:
        `DatabaseIOException`

    - #### setStopReason

          public void setStopReason​(String id,
                                    int stopReason)
                             throws DatabaseIOException

      Description copied from interface: `WritableDownloadIndex`
      Sets the stop reason of the download with the given ID in a terminal state (`Download.STATE_COMPLETED`, `Download.STATE_FAILED`). Does nothing if a download with the given ID does not exist, or if it's not in a terminal state.

      This method may be slow and shouldn't normally be called on the main thread.

      Specified by:
        `setStopReason` in interface `WritableDownloadIndex`
      Parameters:
        `id` - The ID of the download to update.
        `stopReason` - The stop reason.
      Throws:
        `DatabaseIOException`