# AesCipherDataSink

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

*** ** * ** ***

<br />

```
@UnstableApi
class AesCipherDataSink : DataSink
```

<br />

*** ** * ** ***

A wrapping `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink` that encrypts the data being consumed.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/AesCipherDataSink#AesCipherDataSink(byte[],androidx.media3.datasource.DataSink)(secretKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, wrappedDataSink: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink!)` Create an instance whose `write` methods have the side effect of overwriting the input `data`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/AesCipherDataSink#AesCipherDataSink(byte[],androidx.media3.datasource.DataSink,byte[])( secretKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, wrappedDataSink: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink!, scratch: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>? )` Create an instance whose `write` methods are free of side effects. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/AesCipherDataSink#close()()` Closes the sink. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/AesCipherDataSink#open(androidx.media3.datasource.DataSpec)(dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!)` Opens the sink to consume the specified data. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/AesCipherDataSink#write(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)` Consumes the provided data. |

## Public constructors

### AesCipherDataSink

```
AesCipherDataSink(secretKey: ByteArray<Byte>!, wrappedDataSink: DataSink!)
```

Create an instance whose `write` methods have the side effect of overwriting the input `data`. Use this constructor for maximum efficiency in the case that there is no requirement for the input data arrays to remain unchanged.

| Parameters |
|---|---|
| `secretKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The key data. |
| `wrappedDataSink: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink!` | The wrapped `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink`. |

### AesCipherDataSink

```
AesCipherDataSink(
    secretKey: ByteArray<Byte>!,
    wrappedDataSink: DataSink!,
    scratch: ByteArray<Byte>?
)
```

Create an instance whose `write` methods are free of side effects. Use this constructor when the input data arrays are required to remain unchanged.

| Parameters |
|---|---|
| `secretKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The key data. |
| `wrappedDataSink: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink!` | The wrapped `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink`. |
| `scratch: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>?` | Scratch space. Data is encrypted into this array before being written to the wrapped `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink`. It should be of appropriate size for the expected writes. If a write is larger than the size of this array the write will still succeed, but multiple cipher calls will be required to complete the operation. If `null` then encryption will overwrite the input `data`. |

## Public functions

### close

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

Closes the sink.

Note: This method must be called even if the corresponding call to `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink#open(androidx.media3.datasource.DataSpec)` threw an `https://developer.android.com/reference/java/io/IOException.html`. See `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink#open(androidx.media3.datasource.DataSpec)` for more details.

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

### open

```
fun open(dataSpec: DataSpec!): Unit
```

Opens the sink to consume the specified data.

Note: If an `https://developer.android.com/reference/java/io/IOException.html` is thrown, callers must still call `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink#close()` to ensure that any partial effects of the invocation are cleaned up.

| Parameters |
|---|---|
| `dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | Defines the data to be consumed. |

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

### write

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

Consumes the provided data.

| Parameters |
|---|---|
| `buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The buffer from which data should be consumed. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset of the data to consume in `buffer`. |
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The length of the data to consume, in bytes. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs writing to the sink. |