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 对应的本地文件 如果本地 |
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 |
IFileDownloader:IFileDownloader |
remoteFilePath |
String:远程文件。 |
destFile |
File:下载的目标文件。 |
| 抛出 | |
|---|---|
|
com.android.tradefed.build.BuildRetrievalError |
BuildRetrievalError |
|
fetchRemoteFile
public File fetchRemoteFile (IFileDownloader downloader, String remoteFilePath)
返回与给定 remotePath 对应的本地文件
如果本地 File 存在,系统会从缓存中复制该文件;否则,系统会
通过给定的 IFileDownloader 下载该文件。
| 参数 | |
|---|---|
downloader |
IFileDownloader:IFileDownloader |
remoteFilePath |
String:远程文件。 |
| 返回 | |
|---|---|
File |
包含 remotePath 内容的本地 File |
| 抛出 | |
|---|---|
BuildRetrievalError |
如果无法检索文件 |
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 |