文件下載緩存

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)

嘗試釋放文件的鎖。

公共方法

刪除緩存項

public void deleteCacheEntry (String remoteFilePath)

允許從緩存中刪除條目。如果條目無效或損壞。

參數
remoteFilePath String

獲取遠程文件

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

下載文件或將緩存鏈接到目標文件。

參數
downloader IFileDownloaderIFileDownloader

remoteFilePath String : 遠程文件。

destFile File :下載的目標文件。

投擲
com.android.tradefed.build.BuildRetrievalError
BuildRetrievalError

獲取遠程文件

public File fetchRemoteFile (IFileDownloader downloader, 
                String remoteFilePath)

返回對應於給定remotePath的本地文件

如果本地ERROR(/File)存在,將從緩存中復制,否​​則將通過給定的IFileDownloader下載。

參數
downloader IFileDownloaderIFileDownloader

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