public final class CacheUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CacheUtil.CachingCounters
Counters used during caching.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE_BYTES
Default buffer size to be used while caching.
|
static CacheKeyFactory |
DEFAULT_CACHE_KEY_FACTORY
Default
CacheKeyFactory that calls through to getKey(com.google.android.exoplayer2.upstream.DataSpec) . |
Modifier and Type | Method and Description |
---|---|
static void |
cache(DataSpec dataSpec,
Cache cache,
CacheDataSource dataSource,
byte[] buffer,
PriorityTaskManager priorityTaskManager,
int priority,
CacheUtil.CachingCounters counters,
AtomicBoolean isCanceled,
boolean enableEOFException)
Caches the data defined by
dataSpec while skipping already cached data. |
static void |
cache(DataSpec dataSpec,
Cache cache,
DataSource upstream,
CacheUtil.CachingCounters counters,
AtomicBoolean isCanceled)
Caches the data defined by
dataSpec , skipping already cached data. |
static String |
generateKey(Uri uri)
Generates a cache key out of the given
Uri . |
static void |
getCached(DataSpec dataSpec,
Cache cache,
CacheUtil.CachingCounters counters)
Sets a
CacheUtil.CachingCounters to contain the number of bytes already downloaded and the
length for the content defined by a dataSpec . |
static String |
getKey(DataSpec dataSpec)
Returns the
dataSpec.key if not null, otherwise generates a cache key out of dataSpec.uri |
static void |
remove(Cache cache,
String key)
Removes all of the data in the
cache pointed by the key . |
public static final int DEFAULT_BUFFER_SIZE_BYTES
public static final CacheKeyFactory DEFAULT_CACHE_KEY_FACTORY
CacheKeyFactory
that calls through to getKey(com.google.android.exoplayer2.upstream.DataSpec)
.public static String generateKey(Uri uri)
Uri
.uri
- Uri of a content which the requested key is for.public static String getKey(DataSpec dataSpec)
dataSpec.key
if not null, otherwise generates a cache key out of dataSpec.uri
dataSpec
- Defines a content which the requested key is for.public static void getCached(DataSpec dataSpec, Cache cache, CacheUtil.CachingCounters counters)
CacheUtil.CachingCounters
to contain the number of bytes already downloaded and the
length for the content defined by a dataSpec
. CacheUtil.CachingCounters.newlyCachedBytes
is reset to 0.dataSpec
- Defines the data to be checked.cache
- A Cache
which has the data.counters
- The CacheUtil.CachingCounters
to update.public static void cache(DataSpec dataSpec, Cache cache, DataSource upstream, @Nullable CacheUtil.CachingCounters counters, @Nullable AtomicBoolean isCanceled) throws IOException, InterruptedException
dataSpec
, skipping already cached data. Caching stops early
if the end of the input is reached.dataSpec
- Defines the data to be cached.cache
- A Cache
to store the data.upstream
- A DataSource
for reading data not in the cache.counters
- If not null, updated during caching.isCanceled
- An optional flag that will interrupt caching if set to true.IOException
- If an error occurs reading from the source.InterruptedException
- If the thread was interrupted directly or via isCanceled
.public static void cache(DataSpec dataSpec, Cache cache, CacheDataSource dataSource, byte[] buffer, PriorityTaskManager priorityTaskManager, int priority, @Nullable CacheUtil.CachingCounters counters, @Nullable AtomicBoolean isCanceled, boolean enableEOFException) throws IOException, InterruptedException
dataSpec
while skipping already cached data. Caching stops
early if end of input is reached and enableEOFException
is false.
If a PriorityTaskManager
is given, it's used to pause and resume caching depending
on priority
and the priority of other tasks registered to the PriorityTaskManager.
Please note that it's the responsibility of the calling code to call PriorityTaskManager.add(int)
to register with the manager before calling this method, and to call
PriorityTaskManager.remove(int)
afterwards to unregister.
dataSpec
- Defines the data to be cached.cache
- A Cache
to store the data.dataSource
- A CacheDataSource
that works on the cache
.buffer
- The buffer to be used while caching.priorityTaskManager
- If not null it's used to check whether it is allowed to proceed with
caching.priority
- The priority of this task. Used with priorityTaskManager
.counters
- If not null, updated during caching.isCanceled
- An optional flag that will interrupt caching if set to true.enableEOFException
- Whether to throw an EOFException
if end of input has been
reached unexpectedly.IOException
- If an error occurs reading from the source.InterruptedException
- If the thread was interrupted directly or via isCanceled
.