FileDownloadCache

public class FileDownloadCache
extends Object

java.lang.Object
   ↳ com.android.tradefed.build.FileDownloadCache


A helper class that maintains a local filesystem LRU cache of downloaded files.

Summary

Public methods

void deleteCacheEntry(String remoteFilePath)

Allow deleting an entry from the cache.

File fetchRemoteFile(IFileDownloader downloader, String remotePath)

Returns a local file corresponding to the given remotePath

The local File will be copied from the cache if it exists, otherwise will be downloaded via the given IFileDownloader.

void setMaxCacheSize(long numBytes)

Set the maximum size of the local file cache.

Protected methods

void lockFile(String remoteFilePath)

Acquires the lock for a file.

boolean tryLockFile(String remoteFilePath)

Acquire the lock for a file only if it is not held by another thread.

void unlockFile(String remoteFilePath)

Attempt to release a lock for a file.

Public methods

deleteCacheEntry

void deleteCacheEntry (String remoteFilePath)

Allow deleting an entry from the cache. In case the entry is invalid or corrupted.

Parameters
remoteFilePath String

fetchRemoteFile

File fetchRemoteFile (IFileDownloader downloader, 
                String remotePath)

Returns a local file corresponding to the given remotePath

The local File will be copied from the cache if it exists, otherwise will be downloaded via the given IFileDownloader.

Parameters
downloader IFileDownloader: the IFileDownloader

remotePath String: the remote file.

Returns
File a local File containing contents of remotePath

Throws
BuildRetrievalError if file could not be retrieved

setMaxCacheSize

void setMaxCacheSize (long numBytes)

Set the maximum size of the local file cache.

Cache will not be adjusted immediately if set to a smaller size than current, but will take effect on next file download.

Protected methods

lockFile

void lockFile (String remoteFilePath)

Acquires the lock for a file.

Parameters
remoteFilePath String

tryLockFile

boolean tryLockFile (String remoteFilePath)

Acquire the lock for a file only if it is not held by another thread.

Parameters
remoteFilePath String

Returns
boolean true if the lock was acquired, and false otherwise.

unlockFile

void unlockFile (String remoteFilePath)

Attempt to release a lock for a file.

Parameters
remoteFilePath String