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.
|
| 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 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 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.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, CacheUtil.CachingCounters counters) 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 - Counters to update during caching.IOException - If an error occurs reading from the source.InterruptedException - If the thread was interrupted.public static void cache(DataSpec dataSpec, Cache cache, CacheDataSource dataSource, byte[] buffer, PriorityTaskManager priorityTaskManager, int priority, CacheUtil.CachingCounters counters, boolean enableEOFException) throws IOException, InterruptedException
dataSpec while skipping already cached data. Caching stops
early if end of input is reached and enableEOFException is false.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 - Counters to update during caching.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.