Package com.google.android.exoplayer2.upstream.crypto

## Class AesCipherDataSink

- java.lang.Object
- - com.google.android.exoplayer2.upstream.crypto.AesCipherDataSink

- All Implemented Interfaces:
    `DataSink`

      public final class AesCipherDataSink
      extends Object
      implements DataSink

  A wrapping `DataSink` that encrypts the data being consumed.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.DataSink

      `DataSink.Factory`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AesCipherDataSink​(byte[] secretKey, DataSink wrappedDataSink)` | Create an instance whose `write` methods have the side effect of overwriting the input `data`.
    `AesCipherDataSink​(byte[] secretKey, DataSink wrappedDataSink, byte[] scratch)` | Create an instance whose `write` methods are free of side effects.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close()` | Closes the sink.
    `void` | `open​(DataSpec dataSpec)` | Opens the sink to consume the specified data.
    `void` | `write​(byte[] buffer, int offset, int length)` | Consumes the provided data.

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

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

- - ### Constructor Detail

    - #### AesCipherDataSink

          public AesCipherDataSink​(byte[] secretKey,
                                   DataSink wrappedDataSink)

      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` - The key data.
        `wrappedDataSink` - The wrapped `DataSink`.

    - #### AesCipherDataSink

          public AesCipherDataSink​(byte[] secretKey,
                                   DataSink wrappedDataSink,
                                   @Nullable
                                   byte[] scratch)

      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` - The key data.
        `wrappedDataSink` - The wrapped `DataSink`.
        `scratch` - Scratch space. Data is encrypted into this array before being written to the wrapped `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`.

  - ### Method Detail

    - #### open

          public void open​(DataSpec dataSpec)
                    throws IOException

      Description copied from interface: `DataSink`
      Opens the sink to consume the specified data.

      Note: If an `IOException` is thrown, callers must still call `DataSink.close()` to ensure that any partial effects of the invocation are cleaned up.

      Specified by:
        `open` in interface `DataSink`
      Parameters:
        `dataSpec` - Defines the data to be consumed.
      Throws:
        `IOException` - If an error occurs opening the sink.

    - #### write

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

      Description copied from interface: `DataSink`
      Consumes the provided data.
      Specified by:
        `write` in interface `DataSink`
      Parameters:
        `buffer` - The buffer from which data should be consumed.
        `offset` - The offset of the data to consume in `buffer`.
        `length` - The length of the data to consume, in bytes.
      Throws:
        `IOException` - If an error occurs writing to the sink.

    - #### close

          public void close()
                     throws IOException

      Description copied from interface: `DataSink`
      Closes the sink.

      Note: This method must be called even if the corresponding call to `DataSink.open(DataSpec)` threw an `IOException`. See `DataSink.open(DataSpec)` for more details.

      Specified by:
        `close` in interface `DataSink`
      Throws:
        `IOException` - If an error occurs closing the sink.