Class FileCacheDataLoader
- java.lang.Object
-
- eu.europa.esig.dss.service.http.commons.FileCacheDataLoader
-
- All Implemented Interfaces:
DataLoader,Serializable
public class FileCacheDataLoader extends Object implements DataLoader
This class provides some caching features to handle the resources. The default cache folder is set tojava.io.tmpdir. The urls of the resources is transformed to the file name by replacing the special characters by_- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface eu.europa.esig.dss.spi.client.http.DataLoader
DataLoader.DataAndUrl
-
-
Constructor Summary
Constructors Constructor Description FileCacheDataLoader()FileCacheDataLoader(DataLoader dataLoader)
-
Method Summary
Modifier and Type Method Description voidaddToBeIgnored(String urlString)This methods allows to indicate which resources must be ignored.voidaddToBeLoaded(String url)This methods allows to indicate if the resource must be obtained.byte[]get(String url)Execute a HTTP GET operation.byte[]get(String url, boolean refresh)Execute a HTTP GET operation with indication concerning the mandatory nature of the operation.DataLoader.DataAndUrlget(List<String> urlStrings)Execute a HTTP GET operation.DataLoadergetDataLoader()protected booleanisNetworkProtocol(String urlString)byte[]loadFileFromCache(String urlString)Allows to load the file for a given file name from the cache folder.byte[]post(String urlString, byte[] content)Executes a HTTP POST operationvoidsaveBytesInCache(String urlString, byte[] bytes)Allows to add a given array ofbyteas a cache file representing by theurlString.voidsetCacheExpirationTime(long cacheExpirationTimeInMilliseconds)Sets the expiration time for the cached files in milliseconds.voidsetContentType(String contentType)This allows to set the content type.voidsetDataLoader(DataLoader dataLoader)voidsetFileCacheDirectory(File fileCacheDirectory)This method allows to set the file cache directory.voidsetResourceLoader(ResourceLoader resourceLoader)
-
-
-
Constructor Detail
-
FileCacheDataLoader
public FileCacheDataLoader()
-
FileCacheDataLoader
public FileCacheDataLoader(DataLoader dataLoader)
-
-
Method Detail
-
getDataLoader
public DataLoader getDataLoader()
-
setDataLoader
public void setDataLoader(DataLoader dataLoader)
-
setFileCacheDirectory
public void setFileCacheDirectory(File fileCacheDirectory)
This method allows to set the file cache directory. If the cache folder does not exists then it's created.- Parameters:
fileCacheDirectory-Filepointing the cache folder to be used.
-
setCacheExpirationTime
public void setCacheExpirationTime(long cacheExpirationTimeInMilliseconds)
Sets the expiration time for the cached files in milliseconds. If more time has passed from the cache file's last modified time, then a fresh copy is downloaded and cached, otherwise a cached copy is used. If the expiration time is not set, then the cache does not expire.- Parameters:
cacheExpirationTimeInMilliseconds-
-
setResourceLoader
public void setResourceLoader(ResourceLoader resourceLoader)
-
addToBeLoaded
public void addToBeLoaded(String url)
This methods allows to indicate if the resource must be obtained. If this method has been invoked then only the provided URL will be processed.- Parameters:
url- to be processed
-
addToBeIgnored
public void addToBeIgnored(String urlString)
This methods allows to indicate which resources must be ignored. It is useful in a test environment where some of fake sources a not available. It prevents to wait for the timeout.- Parameters:
urlString- to be ignored. It can be the original URL or the cache file name
-
get
public byte[] get(String url, boolean refresh)
Description copied from interface:DataLoaderExecute a HTTP GET operation with indication concerning the mandatory nature of the operation.- Specified by:
getin interfaceDataLoader- Parameters:
url- to accessrefresh- if true indicates that the cached data should be refreshed- Returns:
bytearray of obtained data or null
-
get
public byte[] get(String url)
Description copied from interface:DataLoaderExecute a HTTP GET operation.- Specified by:
getin interfaceDataLoader- Parameters:
url- the url to access- Returns:
bytearray of obtained data or null
-
isNetworkProtocol
protected boolean isNetworkProtocol(String urlString)
-
loadFileFromCache
public byte[] loadFileFromCache(String urlString)
Allows to load the file for a given file name from the cache folder.- Returns:
- the content of the file or
nullif the file does not exist
-
saveBytesInCache
public void saveBytesInCache(String urlString, byte[] bytes)
Allows to add a given array ofbyteas a cache file representing by theurlString.- Parameters:
urlString- the URL to add to the cachebytes- the content of the cache file
-
post
public byte[] post(String urlString, byte[] content) throws DSSException
Description copied from interface:DataLoaderExecutes a HTTP POST operation- Specified by:
postin interfaceDataLoader- Parameters:
urlString- to accesscontent- the content to post- Returns:
bytearray of obtained data- Throws:
DSSException
-
get
public DataLoader.DataAndUrl get(List<String> urlStrings)
Description copied from interface:DataLoaderExecute a HTTP GET operation. This method is used when many URls are available to access the same resource. The operation stops after the first successful download.- Specified by:
getin interfaceDataLoader- Parameters:
urlStrings-ListofStrings representing the URLs to be used in sequential way to obtain the data.- Returns:
DataAndUrlrepresenting the array of obtained data and used url, or null
-
setContentType
public void setContentType(String contentType)
Description copied from interface:DataLoaderThis allows to set the content type. Example: Content-Type "application/ocsp-request"- Specified by:
setContentTypein interfaceDataLoader- Parameters:
contentType- to set the Content-Type
-
-