檔案下載快取
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 |
如果無法擷取檔案 |
setMaxCacheSize
public void setMaxCacheSize (long numBytes)
設定本機檔案快取的大小上限。
如果設定的大小小於目前值,系統不會立即調整快取,但會 會影響下一次下載的檔案
保護方法
鎖定檔案
protected void lockFile (String remoteFilePath)
取得檔案的鎖定。
| 參數 | |
|---|---|
remoteFilePath |
String |
tryLockFile
protected boolean tryLockFile (String remoteFilePath)
僅在檔案未由其他執行緒保留時,才取得鎖定。
| 參數 | |
|---|---|
remoteFilePath |
String |
| 傳回 | |
|---|---|
boolean |
如果有取得鎖定,則為 true,否則傳回 false。 |
解鎖檔案
protected void unlockFile (String remoteFilePath)
嘗試解除檔案的鎖定狀態。
| 參數 | |
|---|---|
remoteFilePath |
String |