CacheWriter
@UnstableApi
public final class CacheWriter
Caching related utility methods.
Summary
Nested types |
|---|
public interface CacheWriter.ProgressListenerReceives progress updates during cache operations. |
Constants |
|
|---|---|
static final int |
DEFAULT_BUFFER_SIZE_BYTES = 131072Default buffer size to be used while caching. |
Public constructors |
|---|
CacheWriter( |
Public methods |
|
|---|---|
void |
Caches the requested data, skipping any that's already cached. |
void |
cancel()Cancels this writer's caching operation. |
Constants
DEFAULT_BUFFER_SIZE_BYTES
public static final int DEFAULT_BUFFER_SIZE_BYTES = 131072
Default buffer size to be used while caching.
Public constructors
CacheWriter
public CacheWriter(
CacheDataSource dataSource,
DataSpec dataSpec,
@Nullable byte[] temporaryBuffer,
@Nullable CacheWriter.ProgressListener progressListener
)
| Parameters | |
|---|---|
CacheDataSource dataSource |
A |
DataSpec dataSpec |
Defines the data to be written. |
@Nullable byte[] temporaryBuffer |
A temporary buffer to be used during caching, or |
@Nullable CacheWriter.ProgressListener progressListener |
An optional progress listener. |
Public methods
cache
@WorkerThread
public void cache()
Caches the requested data, skipping any that's already cached.
If the CacheDataSource used by the writer has a PriorityTaskManager, then it's the responsibility of the caller to call add to register with the manager before calling this method, and to call remove afterwards to unregister. 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.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs reading the data, or writing the data into the cache, or if the operation is canceled. If canceled, an |
cancel
public void cancel()
Cancels this writer's caching operation. cache checks for cancelation frequently during execution, and throws an InterruptedIOException if it sees that the caching operation has been canceled.