Class CachedRegionTracker
- java.lang.Object
-
- com.google.android.exoplayer2.upstream.CachedRegionTracker
-
- All Implemented Interfaces:
Cache.Listener
public final class CachedRegionTracker extends Object implements Cache.Listener
Utility class for efficiently tracking regions of data that are stored in aCache
for a given cache key.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CACHED_TO_END
static int
NOT_CACHED
-
Constructor Summary
Constructors Constructor Description CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getRegionEndTimeMs(long byteOffset)
When provided with a byte offset, this method locates the cached region within which the offset falls, and returns the approximate end position in milliseconds of that region.void
onSpanAdded(Cache cache, CacheSpan span)
Called when aCacheSpan
is added to the cache.void
onSpanRemoved(Cache cache, CacheSpan span)
Called when aCacheSpan
is removed from the cache.void
onSpanTouched(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)
Called when an existingCacheSpan
is touched, causing it to be replaced.void
release()
-
-
-
Field Detail
-
NOT_CACHED
public static final int NOT_CACHED
- See Also:
- Constant Field Values
-
CACHED_TO_END
public static final int CACHED_TO_END
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CachedRegionTracker
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex)
-
-
Method Detail
-
release
public void release()
-
getRegionEndTimeMs
public int getRegionEndTimeMs(long byteOffset)
When provided with a byte offset, this method locates the cached region within which the offset falls, and returns the approximate end position in milliseconds of that region. If the byte offset does not fall within a cached region thenNOT_CACHED
is returned. If the cached region extends to the end of the stream,CACHED_TO_END
is returned.- Parameters:
byteOffset
- The byte offset in the underlying stream.- Returns:
- The end position of the corresponding cache region,
NOT_CACHED
, orCACHED_TO_END
.
-
onSpanAdded
public void onSpanAdded(Cache cache, CacheSpan span)
Description copied from interface:Cache.Listener
Called when aCacheSpan
is added to the cache.- Specified by:
onSpanAdded
in interfaceCache.Listener
- Parameters:
cache
- The source of the event.span
- The addedCacheSpan
.
-
onSpanRemoved
public void onSpanRemoved(Cache cache, CacheSpan span)
Description copied from interface:Cache.Listener
Called when aCacheSpan
is removed from the cache.- Specified by:
onSpanRemoved
in interfaceCache.Listener
- Parameters:
cache
- The source of the event.span
- The removedCacheSpan
.
-
onSpanTouched
public void onSpanTouched(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)
Description copied from interface:Cache.Listener
Called when an existingCacheSpan
is touched, causing it to be replaced. The newCacheSpan
is guaranteed to represent the same data as the one it replaces, howeverCacheSpan.file
andCacheSpan.lastTouchTimestamp
may have changed.Note that for span replacement,
Cache.Listener.onSpanAdded(Cache, CacheSpan)
andCache.Listener.onSpanRemoved(Cache, CacheSpan)
are not called in addition to this method.- Specified by:
onSpanTouched
in interfaceCache.Listener
- Parameters:
cache
- The source of the event.oldSpan
- The oldCacheSpan
, which has been removed from the cache.newSpan
- The newCacheSpan
, which has been added to the cache.
-
-