public final class CacheDataSink extends java.lang.Object implements DataSink
If the DataSpec object used with open(DataSpec) method call has the length field set to C.LENGTH_UNSET but DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH isn't set then write(byte[], int, int) calls
are ignored.
| Modifier and Type | Class and Description |
|---|---|
static class |
CacheDataSink.CacheDataSinkException
Thrown when IOException is encountered when writing data into sink.
|
DataSink.Factory| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
Default buffer size in bytes.
|
| Constructor and Description |
|---|
CacheDataSink(Cache cache,
long maxCacheFileSize)
Constructs a CacheDataSink using the
DEFAULT_BUFFER_SIZE. |
CacheDataSink(Cache cache,
long maxCacheFileSize,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the sink.
|
void |
experimental_setSyncFileDescriptor(boolean syncFileDescriptor)
Sets whether file descriptors are synced when closing output streams.
|
void |
open(DataSpec dataSpec)
Opens the sink to consume the specified data.
|
void |
write(byte[] buffer,
int offset,
int length)
Consumes the provided data.
|
public static final int DEFAULT_BUFFER_SIZE
public CacheDataSink(Cache cache, long maxCacheFileSize)
DEFAULT_BUFFER_SIZE.cache - The cache into which data should be written.maxCacheFileSize - The maximum size of a cache file, in bytes. If the sink is opened for a
DataSpec whose size exceeds this value, then the data will be fragmented into
multiple cache files.public CacheDataSink(Cache cache, long maxCacheFileSize, int bufferSize)
cache - The cache into which data should be written.maxCacheFileSize - The maximum size of a cache file, in bytes. If the sink is opened for a
DataSpec whose size exceeds this value, then the data will be fragmented into
multiple cache files.bufferSize - The buffer size in bytes for writing to a cache file. A zero or negative
value disables buffering.public void experimental_setSyncFileDescriptor(boolean syncFileDescriptor)
This method is experimental, and will be renamed or removed in a future release. It should only be called before the renderer is used.
syncFileDescriptor - Whether file descriptors are synced when closing output streams.public void open(DataSpec dataSpec) throws CacheDataSink.CacheDataSinkException
DataSinkNote: If an IOException is thrown, callers must still call DataSink.close() to
ensure that any partial effects of the invocation are cleaned up.
open in interface DataSinkdataSpec - Defines the data to be consumed.CacheDataSink.CacheDataSinkExceptionpublic void write(byte[] buffer,
int offset,
int length)
throws CacheDataSink.CacheDataSinkException
DataSinkwrite in interface DataSinkbuffer - 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.CacheDataSink.CacheDataSinkExceptionpublic void close()
throws CacheDataSink.CacheDataSinkException
DataSinkNote: This method must be called even if the corresponding call to DataSink.open(DataSpec)
threw an IOException. See DataSink.open(DataSpec) for more details.
close in interface DataSinkCacheDataSink.CacheDataSinkException