public final class CacheUtil
extends java.lang.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.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
cache(DataSpec dataSpec,
Cache cache,
CacheDataSource dataSource,
byte[] buffer,
PriorityTaskManager priorityTaskManager,
int priority,
CacheUtil.CachingCounters counters,
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)
Caches the data defined by
dataSpec, skipping already cached data. |
static java.lang.String |
generateKey(android.net.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 java.lang.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,
java.lang.String key)
Removes all of the data in the
cache pointed by the key. |
public static final int DEFAULT_BUFFER_SIZE_BYTES
public static java.lang.String generateKey(android.net.Uri uri)
Uri.uri - Uri of a content which the requested key is for.public static java.lang.String getKey(DataSpec dataSpec)
dataSpec.key if not null, otherwise generates a cache key out of dataSpec.uridataSpec - 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) throws java.io.IOException, java.lang.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.java.io.IOException - If an error occurs reading from the source.java.lang.InterruptedException - If the thread was interrupted.public static void cache(DataSpec dataSpec, Cache cache, CacheDataSource dataSource, byte[] buffer, PriorityTaskManager priorityTaskManager, int priority, @Nullable CacheUtil.CachingCounters counters, boolean enableEOFException) throws java.io.IOException, java.lang.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.enableEOFException - Whether to throw an EOFException if end of input has been
reached unexpectedly.java.io.IOException - If an error occurs reading from the source.java.lang.InterruptedException - If the thread was interrupted.public static void remove(Cache cache, java.lang.String key)
cache pointed by the key.