文件下载缓存
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的本地文件 如果本地 |
void | setMaxCacheSize (long numBytes) 设置本地文件缓存的最大大小。 |
受保护的方法 | |
---|---|
void | lockFile (String remoteFilePath) 获取文件的锁。 |
boolean | tryLockFile (String remoteFilePath) 仅当文件未被另一个线程持有时才获取该文件的锁。 |
void | unlockFile (String remoteFilePath) 尝试释放文件的锁。 |
公共方法
删除缓存条目
public void deleteCacheEntry (String remoteFilePath)
允许从缓存中删除条目。如果条目无效或损坏。
参数 | |
---|---|
remoteFilePath | String |
获取远程文件
public void fetchRemoteFile (IFileDownloader downloader, String remoteFilePath, File destFile)
下载文件或将缓存链接到目标文件。
参数 | |
---|---|
downloader | IFileDownloader : IFileDownloader |
remoteFilePath | String : 远程文件。 |
destFile | File :下载的目标文件。 |
投掷 | |
---|---|
| com.android.tradefed.build.BuildRetrievalError |
BuildRetrievalError |
获取远程文件
public File fetchRemoteFile (IFileDownloader downloader, String remoteFilePath)
返回对应于给定remotePath的本地文件
如果本地ERROR(/File)
存在,将从缓存中复制,否则将通过给定的IFileDownloader
下载。
参数 | |
---|---|
downloader | IFileDownloader : IFileDownloader |
remoteFilePath | String : 远程文件。 |
退货 | |
---|---|
File | 包含 remotePath 内容的本地ERROR(/File) |
投掷 | |
---|---|
BuildRetrievalError | 如果无法检索文件 |
设置最大缓存大小
public void setMaxCacheSize (long numBytes)
设置本地文件缓存的最大大小。
如果设置为小于当前大小,缓存不会立即调整,但会在下次文件下载时生效。
受保护的方法
锁定文件
protected void lockFile (String remoteFilePath)
获取文件的锁。
参数 | |
---|---|
remoteFilePath | String |
尝试锁定文件
protected boolean tryLockFile (String remoteFilePath)
仅当文件未被另一个线程持有时才获取该文件的锁。
参数 | |
---|---|
remoteFilePath | String |
退货 | |
---|---|
boolean | 如果获取了锁,则为 true,否则为 false。 |
解锁文件
protected void unlockFile (String remoteFilePath)
尝试释放文件的锁。
参数 | |
---|---|
remoteFilePath | String |