# DataSourceUtil

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/DataSourceUtil.java+class:androidx.media3.datasource.DataSourceUtil)

*** ** * ** ***

<br />

```
@UnstableApi
class DataSourceUtil
```

<br />

*** ** * ** ***

Utility methods for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`.

## Summary

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceUtil#closeQuietly(androidx.media3.datasource.DataSource)(dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource?)` Closes a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`, suppressing any `https://developer.android.com/reference/java/io/IOException.html` that may occur. |
| `java-static 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/kotlin/androidx/media3/datasource/DataSourceUtil#readExactly(androidx.media3.datasource.DataSource,int)(dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads `length` bytes from the specified opened `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`, and returns a byte array containing the read data. |
| `java-static 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/kotlin/androidx/media3/datasource/DataSourceUtil#readToEnd(androidx.media3.datasource.DataSource)(dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!)` Reads data from the specified opened `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` until it ends, and returns a byte array containing the read data. |

## Public functions

### closeQuietly

```
java-static fun closeQuietly(dataSource: DataSource?): Unit
```

Closes a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`, suppressing any `https://developer.android.com/reference/java/io/IOException.html` that may occur.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource?` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` to close. |

### readExactly

```
java-static fun readExactly(dataSource: DataSource!, length: Int): Array<Byte>!
```

Reads `length` bytes from the specified opened `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`, and returns a byte array containing the read data.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which to read. |
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes to read. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The read data. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading from the source. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the end of the source was reached before `length` bytes could be read. |

### readToEnd

```
java-static fun readToEnd(dataSource: DataSource!): Array<Byte>!
```

Reads data from the specified opened `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` until it ends, and returns a byte array containing the read data.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which to read. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The concatenation of all read data. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading from the source. |