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.

void fetchRemoteFile(IFileDownloader downloader, String remoteFilePath, File destFile)

Download the file or link the cache to the destination file.

File fetchRemoteFile(IFileDownloader downloader, String remoteFilePath)

Returns a local file corresponding to the given remotePath

The local ERROR(/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

public void deleteCacheEntry (String remoteFilePath)

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

Parameters
remoteFilePath String

fetchRemoteFile

public void fetchRemoteFile (IFileDownloader downloader, 
                String remoteFilePath, 
                File destFile)

Download the file or link the cache to the destination file.

Parameters
downloader IFileDownloader: the IFileDownloader

remoteFilePath String: the remote file.

destFile File: The destination file of the download.

Throws
com.android.tradefed.build.BuildRetrievalError
BuildRetrievalError

fetchRemoteFile

public File fetchRemoteFile (IFileDownloader downloader, 
                String remoteFilePath)

Returns a local file corresponding to the given remotePath

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

Parameters
downloader IFileDownloader: the IFileDownloader

remoteFilePath String: the remote file.

Returns
File a local ERROR(/File) containing contents of remotePath

Throws
BuildRetrievalError if file could not be retrieved

setMaxCacheSize

public 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

protected void lockFile (String remoteFilePath)

Acquires the lock for a file.

Parameters
remoteFilePath String

tryLockFile

protected 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

protected void unlockFile (String remoteFilePath)

Attempt to release a lock for a file.

Parameters
remoteFilePath String