Class RemoteFile
-
- All Implemented Interfaces:
public final class RemoteFileRemote file
A remote file is used when we need to download content from a remote location and keep a local cached copy of it. It also supports expiring the cached copy or using a fallback local file if there is no connection available.
-
-
Field Summary
Fields Modifier and Type Field Description private StringremoteFileContentprivate final StringcacheFileDateKeyprivate final StringremoteFileURLprivate final BooleanvalidateRemoteFileAsJSONprivate final StringcacheFileNameprivate final IntegercacheFileExpirationInSecondsprivate final StringfallbackFilePathInAssetsprivate final BooleanisUpdateCacheImmediatelyprivate LongupdateTimeoutprivate BooleanisBlockUntilUpdated
-
Constructor Summary
Constructors Constructor Description RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets, Boolean isUpdateCacheImmediately, Long updateTimeout, Boolean isBlockUntilUpdated)RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets, Boolean isUpdateCacheImmediately, Long updateTimeout)RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets, Boolean isUpdateCacheImmediately)RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets)
-
Method Summary
Modifier and Type Method Description final StringgetRemoteFileContent()Content of the remote file final UnitsetRemoteFileContent(String remoteFileContent)Content of the remote file final StringgetCacheFileDateKey()Shared preferences key to hold the date when the cache file was last updated final StringgetRemoteFileURL()URL of the file to download final BooleangetValidateRemoteFileAsJSON()Whether the downloaded file should be validated as JSON before being returned and cached final StringgetCacheFileName()File name to use when caching the remote file locally final IntegergetCacheFileExpirationInSeconds()Number of seconds before refreshing the local cache final StringgetFallbackFilePathInAssets()Name of a file in the assets/ folder to use as fall back if there is no connection and no cached version final BooleanisUpdateCacheImmediately()Whether the cache should be updated from remote immediately if needed (blocking operation). final LonggetUpdateTimeout()Timeout before abandon getting file content from remote, in milliseconds final UnitsetUpdateTimeout(Long updateTimeout)Timeout before abandon getting file content from remote, in milliseconds final BooleanisBlockUntilUpdated()Whether to try getting content from remote without timeout final UnitsetBlockUntilUpdated(Boolean isBlockUntilUpdated)Whether to try getting content from remote without timeout final BooleanshouldRetryCacheUpdate()final BooleanisCacheEnabled()final BooleanisRemoteEnabled()-
-
Constructor Detail
-
RemoteFile
RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets, Boolean isUpdateCacheImmediately, Long updateTimeout, Boolean isBlockUntilUpdated)
-
RemoteFile
RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets, Boolean isUpdateCacheImmediately, Long updateTimeout)
-
RemoteFile
RemoteFile(String remoteFileURL, Boolean validateRemoteFileAsJSON, String cacheFileName, Integer cacheFileExpirationInSeconds, String fallbackFilePathInAssets, Boolean isUpdateCacheImmediately)
-
-
Method Detail
-
getRemoteFileContent
final String getRemoteFileContent()
Content of the remote file
-
setRemoteFileContent
final Unit setRemoteFileContent(String remoteFileContent)
Content of the remote file
-
getCacheFileDateKey
final String getCacheFileDateKey()
Shared preferences key to hold the date when the cache file was last updated
-
getRemoteFileURL
final String getRemoteFileURL()
URL of the file to download
-
getValidateRemoteFileAsJSON
final Boolean getValidateRemoteFileAsJSON()
Whether the downloaded file should be validated as JSON before being returned and cached
-
getCacheFileName
final String getCacheFileName()
File name to use when caching the remote file locally
-
getCacheFileExpirationInSeconds
final Integer getCacheFileExpirationInSeconds()
Number of seconds before refreshing the local cache
-
getFallbackFilePathInAssets
final String getFallbackFilePathInAssets()
Name of a file in the assets/ folder to use as fall back if there is no connection and no cached version
-
isUpdateCacheImmediately
final Boolean isUpdateCacheImmediately()
Whether the cache should be updated from remote immediately if needed (blocking operation). Otherwise, if a cache exists, it is not updated and needs to be updated later.
-
getUpdateTimeout
final Long getUpdateTimeout()
Timeout before abandon getting file content from remote, in milliseconds
-
setUpdateTimeout
final Unit setUpdateTimeout(Long updateTimeout)
Timeout before abandon getting file content from remote, in milliseconds
-
isBlockUntilUpdated
final Boolean isBlockUntilUpdated()
Whether to try getting content from remote without timeout
-
setBlockUntilUpdated
final Unit setBlockUntilUpdated(Boolean isBlockUntilUpdated)
Whether to try getting content from remote without timeout
-
shouldRetryCacheUpdate
final Boolean shouldRetryCacheUpdate()
-
isCacheEnabled
final Boolean isCacheEnabled()
-
isRemoteEnabled
final Boolean isRemoteEnabled()
-
-
-
-