Package com.google.android.exoplayer2.upstream

## Class DataSourceInputStream

- java.lang.Object
- - java.io.InputStream
  - - com.google.android.exoplayer2.upstream.DataSourceInputStream

- All Implemented Interfaces:
    `Closeable`, `AutoCloseable`

      public final class DataSourceInputStream
      extends InputStream

  Allows data corresponding to a given `DataSpec` to be read from a `DataSource` and consumed through an `InputStream`.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DataSourceInputStream​(DataSource dataSource, DataSpec dataSpec)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `long` | `bytesRead()` | Returns the total number of bytes that have been read or skipped.
    `void` | `close()` |
    `void` | `open()` | Optional call to open the underlying `DataSource`.
    `int` | `read()` |
    `int` | `read​(byte[] buffer)` |
    `int` | `read​(byte[] buffer, int offset, int length)` |

    - ### Methods inherited from class java.io.InputStream

      `available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo`

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

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

- - ### Constructor Detail

    - #### DataSourceInputStream

          public DataSourceInputStream​(DataSource dataSource,
                                       DataSpec dataSpec)

      Parameters:
        `dataSource` - The `DataSource` from which the data should be read.
        `dataSpec` - The `DataSpec` defining the data to be read from `dataSource`.

  - ### Method Detail

    - #### bytesRead

          public long bytesRead()

      Returns the total number of bytes that have been read or skipped.

    - #### open

          public void open()
                    throws IOException

      Optional call to open the underlying `DataSource`.

      Calling this method does nothing if the `DataSource` is already open. Calling this method is optional, since the read and skip methods will automatically open the underlying `DataSource` if it's not open already.

      Throws:
        `IOException` - If an error occurs opening the `DataSource`.

    - #### read

          public int read()
                   throws IOException

      Specified by:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### read

          public int read​(byte[] buffer)
                   throws IOException

      Overrides:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### read

          public int read​(byte[] buffer,
                          int offset,
                          int length)
                   throws IOException

      Overrides:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Closeable`
      Overrides:
        `close` in class `InputStream`
      Throws:
        `IOException`