# FakeDataSet

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

*** ** * ** ***

<br />

```
@UnstableApi
class FakeDataSet
```

<br />

Known direct subclasses [FakeAdaptiveDataSet](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdaptiveDataSet)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdaptiveDataSet` | Fake data set emulating the data of an adaptive media source. |

*** ** * ** ***

Collection of `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` to be served by a `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSource`.

Multiple fake data can be defined by `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#setData(android.net.Uri,byte[])` and `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newData(android.net.Uri)` methods. It's also possible to define a default data by `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newDefaultData()`.

`https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newData(android.net.Uri)` and `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newDefaultData()` return a `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` instance which can be used to define specific results during `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSource#read(byte[],int,int)` calls.

The data that will be read from the source can be constructed by calling `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData#appendReadData(byte[])` Calls to `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSource#read(byte[],int,int)` will not span the boundaries between arrays passed to successive calls, and hence the boundaries control the positions at which read requests to the source may only be partially satisfied.

Errors can be inserted by calling `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData#appendReadError(java.io.IOException)`. An inserted error will be thrown from the first call to `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSource#read(byte[],int,int)` that attempts to read from the corresponding position, and from all subsequent calls to `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSource#read(byte[],int,int)` until the source is closed. If the source is closed and re-opened having encountered an error, that error will not be thrown again.

Actions are inserted by calling `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData#appendReadAction(java.lang.Runnable)`. An actions is triggered when the reading reaches action's position. This can be used to make sure the code is in a certain state while testing.

Example usage:

```kotlin
  // Create a FakeDataSource then add default data and two FakeData
  // "test_file" throws an IOException when tried to be read until closed and reopened.
  FakeDataSource fakeDataSource = new FakeDataSource();
  fakeDataSource.getDataSet()
      .newDefaultData()
        .appendReadData(defaultData)
        .endData()
      .setData("http://1", data1)
      .newData("test_file")
        .appendReadError(new IOException())
        .appendReadData(data2)
        .endData();
```

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` Container of fake data to be served by a `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSource`. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData.Segment` A segment of `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#FakeDataSet()()` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#getAllData()()` Returns a list of all data including `defaultData`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData?` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#getData(java.lang.String)(uri: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Returns the data for the given `uri`, or `defaultData` if no data is set. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData?` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#getData(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html!)` Returns the data for the given `uri`, or `defaultData` if no data is set. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newData(java.lang.String)(uri: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Returns a new `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` with the given `uri`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newData(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html!)` Returns a new `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` with the given `uri`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#newDefaultData()()` Sets the default data, overwrites if there is one already. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#setData(java.lang.String,byte[])(uri: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Sets the given `data` for the given `uri`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#setData(android.net.Uri,byte[])(uri: https://developer.android.com/reference/android/net/Uri.html!, data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Sets the given `data` for the given `uri`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#setRandomData(java.lang.String,int)(uri: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets random data with the given `length` for the given `uri`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet#setRandomData(android.net.Uri,int)(uri: https://developer.android.com/reference/android/net/Uri.html!, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets random data with the given `length` for the given `uri`. |

## Public constructors

### FakeDataSet

```
FakeDataSet()
```

## Public functions

### getAllData

```
fun getAllData(): ArrayList<FakeDataSet.FakeData!>!
```

Returns a list of all data including `defaultData`.

### getData

```
fun getData(uri: String!): FakeDataSet.FakeData?
```

Returns the data for the given `uri`, or `defaultData` if no data is set.

### getData

```
fun getData(uri: Uri!): FakeDataSet.FakeData?
```

Returns the data for the given `uri`, or `defaultData` if no data is set.

### newData

```
fun newData(uri: String!): FakeDataSet.FakeData!
```

Returns a new `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` with the given `uri`.

### newData

```
fun newData(uri: Uri!): FakeDataSet.FakeData!
```

Returns a new `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet.FakeData` with the given `uri`.

### newDefaultData

```
fun newDefaultData(): FakeDataSet.FakeData!
```

Sets the default data, overwrites if there is one already.

### setData

```
fun setData(uri: String!, data: ByteArray<Byte>!): FakeDataSet!
```

Sets the given `data` for the given `uri`.

### setData

```
fun setData(uri: Uri!, data: ByteArray<Byte>!): FakeDataSet!
```

Sets the given `data` for the given `uri`.

### setRandomData

```
fun setRandomData(uri: String!, length: Int): FakeDataSet!
```

Sets random data with the given `length` for the given `uri`.

### setRandomData

```
fun setRandomData(uri: Uri!, length: Int): FakeDataSet!
```

Sets random data with the given `length` for the given `uri`.