Class CacheWriter


  • public final class CacheWriter
    extends Object
    Caching related utility methods.
    • Field Detail

      • DEFAULT_BUFFER_SIZE_BYTES

        public static final int DEFAULT_BUFFER_SIZE_BYTES
        Default buffer size to be used while caching.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CacheWriter

        public CacheWriter​(CacheDataSource dataSource,
                           DataSpec dataSpec,
                           boolean allowShortContent,
                           @Nullable
                           byte[] temporaryBuffer,
                           @Nullable
                           CacheWriter.ProgressListener progressListener)
        Parameters:
        dataSource - A CacheDataSource that 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 DataSpec. If true and the request exceeds the length of the content, then the content will be cached to the end. If false and the request exceeds the length of the content, cache will throw an IOException.
        temporaryBuffer - A temporary buffer to be used during caching, or null if the writer should instantiate its own internal temporary buffer.
        progressListener - An optional progress listener.
    • Method Detail

      • 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.