Class CacheDataSink
- java.lang.Object
-
- com.google.android.exoplayer2.upstream.cache.CacheDataSink
-
- All Implemented Interfaces:
DataSink
@Deprecated public final class CacheDataSink extends Object implements DataSink
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.Writes data into a cache.If the
DataSpecpassed toopen(DataSpec)has thelengthfield set toC.LENGTH_UNSETandDataSpec.FLAG_DONT_CACHE_IF_LENGTH_UNKNOWNset, thenwrite(byte[], int, int)calls are ignored.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCacheDataSink.CacheDataSinkExceptionDeprecated.Thrown when anIOExceptionis encountered when writing data to the sink.static classCacheDataSink.FactoryDeprecated.DataSink.FactoryforCacheDataSinkinstances.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDeprecated.Default buffer size in bytes.static longDEFAULT_FRAGMENT_SIZEDeprecated.DefaultfragmentSizerecommended for caching use cases.
-
Constructor Summary
Constructors Constructor Description CacheDataSink(Cache cache, long fragmentSize)Deprecated.Constructs an instance usingDEFAULT_BUFFER_SIZE.CacheDataSink(Cache cache, long fragmentSize, int bufferSize)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Deprecated.Closes the sink.voidopen(DataSpec dataSpec)Deprecated.Opens the sink to consume the specified data.voidwrite(byte[] buffer, int offset, int length)Deprecated.Consumes the provided data.
-
-
-
Field Detail
-
DEFAULT_FRAGMENT_SIZE
public static final long DEFAULT_FRAGMENT_SIZE
Deprecated.DefaultfragmentSizerecommended for caching use cases.- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Deprecated.Default buffer size in bytes.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CacheDataSink
public CacheDataSink(Cache cache, long fragmentSize)
Deprecated.Constructs an instance usingDEFAULT_BUFFER_SIZE.- Parameters:
cache- The cache into which data should be written.fragmentSize- For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set toC.LENGTH_UNSETthen no fragmentation will occur. Using a small value allows for finer-grained cache eviction policies, at the cost of increased overhead both on the cache implementation and the file system. Values under(2 * 1024 * 1024)are not recommended.
-
CacheDataSink
public CacheDataSink(Cache cache, long fragmentSize, int bufferSize)
Deprecated.- Parameters:
cache- The cache into which data should be written.fragmentSize- For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set toC.LENGTH_UNSETthen no fragmentation will occur. Using a small value allows for finer-grained cache eviction policies, at the cost of increased overhead both on the cache implementation and the file system. Values under(2 * 1024 * 1024)are not recommended.bufferSize- The buffer size in bytes for writing to a cache file. A zero or negative value disables buffering.
-
-
Method Detail
-
open
public void open(DataSpec dataSpec) throws CacheDataSink.CacheDataSinkException
Deprecated.Description copied from interface:DataSinkOpens the sink to consume the specified data.Note: If an
IOExceptionis thrown, callers must still callDataSink.close()to ensure that any partial effects of the invocation are cleaned up.- Specified by:
openin interfaceDataSink- Parameters:
dataSpec- Defines the data to be consumed.- Throws:
CacheDataSink.CacheDataSinkException
-
write
public void write(byte[] buffer, int offset, int length) throws CacheDataSink.CacheDataSinkExceptionDeprecated.Description copied from interface:DataSinkConsumes the provided data.- Specified by:
writein interfaceDataSink- Parameters:
buffer- The buffer from which data should be consumed.offset- The offset of the data to consume inbuffer.length- The length of the data to consume, in bytes.- Throws:
CacheDataSink.CacheDataSinkException
-
close
public void close() throws CacheDataSink.CacheDataSinkExceptionDeprecated.Description copied from interface:DataSinkCloses the sink.Note: This method must be called even if the corresponding call to
DataSink.open(DataSpec)threw anIOException. SeeDataSink.open(DataSpec)for more details.- Specified by:
closein interfaceDataSink- Throws:
CacheDataSink.CacheDataSinkException
-
-