Back to Exoplayer

FailOnCloseDataSink (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/testutil/FailOnCloseDataSink.html

latest5.0 KB
Original Source

Package com.google.android.exoplayer2.testutil

Class FailOnCloseDataSink

  • java.lang.Object

    • com.google.android.exoplayer2.testutil.FailOnCloseDataSink
  • All Implemented Interfaces:DataSink


public final classFailOnCloseDataSinkextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[DataSink](../upstream/DataSink.html "interface in com.google.android.exoplayer2.upstream")

A DataSink that can simulate caching the bytes being written to it, and then failing to persist them when close() is called.

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static class | FailOnCloseDataSink.Factory | Factory to create a FailOnCloseDataSink. |

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | FailOnCloseDataSink​(Cache cache, AtomicBoolean failOnClose) | Creates an instance. |

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

- 

FailOnCloseDataSink

public FailOnCloseDataSink​([Cache](../upstream/cache/Cache.html "interface in com.google.android.exoplayer2.upstream.cache")cache,[AtomicBoolean](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicBoolean.html "class or interface in java.util.concurrent.atomic")failOnClose)

Creates an instance. Parameters:cache - The cache to write to when not in fail-on-close mode.failOnClose - An AtomicBoolean whose value is read in each call to open(com.google.android.exoplayer2.upstream.DataSpec) to determine whether to enable fail-on-close for the read that's being started.

Method Detail

- 

open

public void open​([DataSpec](../upstream/DataSpec.html "class in com.google.android.exoplayer2.upstream")dataSpec)
          throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")

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 DataSinkParameters: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](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")

Description copied from interface: DataSink

Consumes the provided data. Specified by:write in interface DataSinkParameters: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](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")

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 DataSinkThrows:IOException - If an error occurs closing the sink.