CacheDataSink
@UnstableApi
class CacheDataSink : DataSink
Writes data into a cache.
If the DataSpec passed to open has the length field set to LENGTH_UNSET and FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN set, then write calls are ignored.
Summary
Nested types |
|---|
|
Thrown when an |
|
|
Constants |
|
|---|---|
const Int |
DEFAULT_BUFFER_SIZE = 20480Default buffer size in bytes. |
const Long |
DEFAULT_FRAGMENT_SIZE = 5242880Default |
Public constructors |
|---|
CacheDataSink(cache: Cache!, fragmentSize: Long)Constructs an instance using |
CacheDataSink(cache: Cache!, fragmentSize: Long, bufferSize: Int) |
Public functions |
|
|---|---|
Unit |
close()Closes the sink. |
Unit |
Opens the sink to consume the specified data. |
Unit |
Consumes the provided data. |
Constants
DEFAULT_FRAGMENT_SIZE
const val DEFAULT_FRAGMENT_SIZE = 5242880: Long
Default fragmentSize recommended for caching use cases.
Public constructors
CacheDataSink
CacheDataSink(cache: Cache!, fragmentSize: Long)
Constructs an instance using DEFAULT_BUFFER_SIZE.
| Parameters | |
|---|---|
cache: Cache! |
The cache into which data should be written. |
fragmentSize: Long |
For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set to |
CacheDataSink
CacheDataSink(cache: Cache!, fragmentSize: Long, bufferSize: Int)
| Parameters | |
|---|---|
cache: Cache! |
The cache into which data should be written. |
fragmentSize: Long |
For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set to |
bufferSize: Int |
The buffer size in bytes for writing to a cache file. A zero or negative value disables buffering. |
Public functions
close
fun close(): Unit
Closes the sink.
Note: This method must be called even if the corresponding call to open threw an IOException. See open for more details.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs closing the sink. |
androidx.media3.datasource.cache.CacheDataSink.CacheDataSinkException |
open
fun open(dataSpec: DataSpec!): Unit
Opens the sink to consume the specified data.
Note: If an IOException is thrown, callers must still call close to ensure that any partial effects of the invocation are cleaned up.
| Parameters | |
|---|---|
dataSpec: DataSpec! |
Defines the data to be consumed. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs opening the sink. |
androidx.media3.datasource.cache.CacheDataSink.CacheDataSinkException |
write
fun write(buffer: ByteArray!, offset: Int, length: Int): Unit
Consumes the provided data.
| Parameters | |
|---|---|
buffer: ByteArray! |
The buffer from which data should be consumed. |
offset: Int |
The offset of the data to consume in |
length: Int |
The length of the data to consume, in bytes. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs writing to the sink. |
androidx.media3.datasource.cache.CacheDataSink.CacheDataSinkException |