# DataSourceInputStream

Artifact: [androidx.media3:media3-datasource](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/datasource/DataSourceInputStream.java+class:androidx.media3.datasource.DataSourceInputStream)

*** ** * ** ***

<br />

```
@UnstableApi
class DataSourceInputStream : InputStream
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [java.io.InputStream](https://developer.android.com/reference/java/io/InputStream.html) ||
|   | ↳ | [androidx.media3.datasource.DataSourceInputStream](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream) |

*** ** * ** ***

Allows data corresponding to a given `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec` to be read from a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` and consumed through an `https://developer.android.com/reference/java/io/InputStream.html`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#DataSourceInputStream(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec)(dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!)` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#bytesRead()()` Returns the total number of bytes that have been read or skipped. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#close()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#open()()` Optional call to open the underlying `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#read()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#read(byte[])(buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceInputStream#read(byte[],int,int)(buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |

### Inherited functions

From [java.io.InputStream](https://developer.android.com/reference/java/io/InputStream.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/io/InputStream.html#available()()` `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/io/InputStream.html#mark(int)(readlimit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/io/InputStream.html#markSupported()()` `java-static https://developer.android.com/reference/java/io/InputStream.html!` `https://developer.android.com/reference/java/io/InputStream.html#nullInputStream()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` `https://developer.android.com/reference/java/io/InputStream.html#readAllBytes()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` `https://developer.android.com/reference/java/io/InputStream.html#readNBytes(int)(len: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/io/InputStream.html#readNBytes(byte[], int, int)(b: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, off: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, len: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/io/InputStream.html#reset()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/java/io/InputStream.html#skip(long)(n: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/io/InputStream.html#skipNBytes(long)(n: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/java/io/InputStream.html#transferTo(java.io.OutputStream)(out: https://developer.android.com/reference/java/io/OutputStream.html!)`

## Public constructors

### DataSourceInputStream

```
DataSourceInputStream(dataSource: DataSource!, dataSpec: DataSpec!)
```

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` from which the data should be read. |
| `dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec` defining the data to be read from `dataSource`. |

## Public functions

### bytesRead

```
fun bytesRead(): Long
```

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

### close

```
fun close(): Unit
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### open

```
fun open(): Unit
```

Optional call to open the underlying `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`.

Calling this method does nothing if the `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` is already open. Calling this method is optional, since the read and skip methods will automatically open the underlying `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` if it's not open already.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs opening the `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`. |

### read

```
fun read(): Int
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### read

```
fun read(buffer: ByteArray<Byte>!): Int
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### read

```
fun read(buffer: ByteArray<Byte>!, offset: Int, length: Int): Int
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |