FileDownloadCache

public class FileDownloadCache
extends Object

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


一个辅助类,用于维护下载文件的本地文件系统 LRU 缓存。

摘要

公共方法

void deleteCacheEntry(String remoteFilePath)

允许从缓存中删除条目。

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

下载文件或将缓存关联到目标文件。

File fetchRemoteFile(IFileDownloader downloader, String remoteFilePath)

返回与给定 remotePath 对应的本地文件

系统会从缓存中复制本地 ERROR(/File)(如果存在),否则会通过给定的 IFileDownloader 下载。

void setMaxCacheSize(long numBytes)

设置本地文件缓存的大小上限。

受保护的方法

void lockFile(String remoteFilePath)

获取文件的锁。

boolean tryLockFile(String remoteFilePath)

仅当文件未被其他线程持有时,才获取文件的锁。

void unlockFile(String remoteFilePath)

尝试释放文件的锁定。

公共方法

deleteCacheEntry

public void deleteCacheEntry (String remoteFilePath)

允许从缓存中删除条目。如果条目无效或损坏。

参数
remoteFilePath String

fetchRemoteFile

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

下载文件或将缓存关联到目标文件。

参数
downloader IFileDownloaderIFileDownloader

remoteFilePath String:远程文件。

destFile File:下载内容的目标文件。

抛出
BuildRetrievalError

fetchRemoteFile

public File fetchRemoteFile (IFileDownloader downloader, 
                String remoteFilePath)

返回与给定 remotePath 对应的本地文件

系统会从缓存中复制本地 ERROR(/File)(如果存在),否则会通过给定的 IFileDownloader 下载。

参数
downloader IFileDownloaderIFileDownloader

remoteFilePath String:远程文件。

返回
File 包含 remotePath 内容的本地 ERROR(/File)

抛出
BuildRetrievalError if file could not be retrieved

setMaxCacheSize

public void setMaxCacheSize (long numBytes)

设置本地文件缓存的大小上限。

如果将缓存设置为小于当前大小,系统不会立即进行调整,但会在下次下载文件时生效。

受保护的方法

lockFile

protected void lockFile (String remoteFilePath)

获取文件的锁。

参数
remoteFilePath String

tryLockFile

protected boolean tryLockFile (String remoteFilePath)

仅当文件未被其他线程持有时,才会获取文件的锁。

参数
remoteFilePath String

返回
boolean 如果已获取锁,则为 true,否则为 false。

unlockFile

protected void unlockFile (String remoteFilePath)

尝试释放文件的锁定。

参数
remoteFilePath String