public final class CacheWriter extends Object
|Modifier and Type||Class and Description|
Receives progress updates during cache operations.
|Modifier and Type||Field and Description|
Default buffer size to be used while caching.
|Constructor and Description|
|Modifier and Type||Method and Description|
Caches the requested data, skipping any that's already cached.
Cancels this writer's caching operation.
public static final int DEFAULT_BUFFER_SIZE_BYTES
public CacheWriter(CacheDataSource dataSource, DataSpec dataSpec, boolean allowShortContent, @Nullable byte temporaryBuffer, @Nullable CacheWriter.ProgressListener progressListener)
CacheDataSourcethat writes to the target cache.
dataSpec- Defines the data to be written.
allowShortContent- Whether it's allowed for the content to end before the request as defined by the
trueand the request exceeds the length of the content, then the content will be cached to the end. If
falseand the request exceeds the length of the content,
cachewill throw an
temporaryBuffer- A temporary buffer to be used during caching, or
nullif the writer should instantiate its own internal temporary buffer.
progressListener- An optional progress listener.
public void cancel()
@WorkerThread public void cache() throws IOException
CacheDataSource used by the writer has a
it's the responsibility of the caller to call
PriorityTaskManager.add(int) to register with
the manager before calling this method, and to call
afterwards to unregister.
PriorityTaskManager.PriorityTooLowException will be thrown if the priority
required by the
CacheDataSource is not high enough for progress to be made.
This method may be slow and shouldn't normally be called on the main thread.