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 相對應的本機檔案

如果快取中存在本機 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:下載的目的地檔案。

擲回
com.android.tradefed.build.BuildRetrievalError
BuildRetrievalError

fetchRemoteFile

public File fetchRemoteFile (IFileDownloader downloader, 
                String remoteFilePath)

傳回與指定 remotePath 相對應的本機檔案

如果快取中存在本機 File,系統會從快取複製,否則會透過指定的 IFileDownloader 下載。

參數
downloader IFileDownloaderIFileDownloader

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