java.lang.Object
eu.europa.esig.dss.service.http.commons.FileCacheDataLoader
- All Implemented Interfaces:
eu.europa.esig.dss.spi.client.http.DataLoader,eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader,eu.europa.esig.dss.spi.client.http.DSSFileLoader,Serializable
public class FileCacheDataLoader
extends Object
implements eu.europa.esig.dss.spi.client.http.DataLoader, eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
This class provides some caching features to handle the resources. The default cache folder is set to
java.io.tmpdir. The urls of the resources is transformed to the
file name by replacing the special characters by _- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.europa.esig.dss.spi.client.http.DataLoader
eu.europa.esig.dss.spi.client.http.DataLoader.DataAndUrl -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructorFileCacheDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader) Default constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToBeIgnored(String urlString) This method allow indicating which resources must be ignored.voidaddToBeLoaded(String url) This method allow indicating if the resource must be obtained.createFile(String urlString, byte[] bytes) Allows to add a given array ofbyteas a cache file representing by theurl.byte[]byte[]Executes a GET request to the provided URL, with a forced cacherefreshwhen definedeu.europa.esig.dss.spi.client.http.DataLoader.DataAndUrleu.europa.esig.dss.spi.client.http.DataLoaderGets the dataloadereu.europa.esig.dss.model.DSSDocumentgetDocument(String url) eu.europa.esig.dss.model.DSSDocumentgetDocument(String url, boolean refresh) This method allows to download aDSSDocumentfrom a specifiedurlwith a custom setting indicating whether therefreshof the document's cache shall be enforced, when applicableeu.europa.esig.dss.model.DSSDocumentprotected booleanisNetworkProtocol(String urlString) Checks if the URL defines a network protocolbyte[]booleanvoidsetCacheExpirationTime(long cacheExpirationTimeInMilliseconds) Sets the expiration time for the cached files in milliseconds.voidsetContentType(String contentType) voidsetDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader) Sets the data loader for a remote documents access (e.g. online)voidsetFileCacheDirectory(File fileCacheDirectory) This method allows to set the file cache directory.voidsetResourceLoader(ResourceLoader resourceLoader) Sets the ResourceLoader for an absolute path creation
-
Constructor Details
-
FileCacheDataLoader
public FileCacheDataLoader()Empty constructor -
FileCacheDataLoader
public FileCacheDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader) Default constructor- Parameters:
dataLoader-DataLoaderto use for remote access (e.g. online)
-
-
Method Details
-
getDataLoader
public eu.europa.esig.dss.spi.client.http.DataLoader getDataLoader()Gets the dataloader- Returns:
DataLoader
-
setDataLoader
public void setDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader) Sets the data loader for a remote documents access (e.g. online)- Parameters:
dataLoader-DataLoader
-
setFileCacheDirectory
This method allows to set the file cache directory. If the cache folder does not exist 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 the defined time has passed after the cache file's last modification time, then a fresh copy is downloaded and cached, otherwise a cached copy is used.A negative value is interpreted as undefined (cache does not expire).
Default:
-1- Parameters:
cacheExpirationTimeInMilliseconds- value in milliseconds
-
setResourceLoader
Sets the ResourceLoader for an absolute path creation- Parameters:
resourceLoader-ResourceLoader
-
addToBeLoaded
This method allow indicating 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
This method allow indicating which resources must be ignored. It is useful in a test environment where some of fake sources are 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
Executes a GET request to the provided URL, with a forced cacherefreshwhen defined- Parameters:
url- to accessrefresh- if true indicates that the cached data should be refreshed- Returns:
- binaries of the extracted data object
-
get
- Specified by:
getin interfaceeu.europa.esig.dss.spi.client.http.DataLoader- Throws:
eu.europa.esig.dss.model.DSSException
-
getDocument
This method allows to download aDSSDocumentfrom a specifiedurlwith a custom setting indicating whether therefreshof the document's cache shall be enforced, when applicable- Specified by:
getDocumentin interfaceeu.europa.esig.dss.spi.client.http.DSSCacheFileLoader- Parameters:
url-Stringremote location of the document to downloadrefresh- indicates whether the refresh of the cached document shall be enforced- Returns:
DSSDocument
-
getDocument
- Specified by:
getDocumentin interfaceeu.europa.esig.dss.spi.client.http.DSSFileLoader
-
remove
- Specified by:
removein interfaceeu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
-
isNetworkProtocol
Checks if the URL defines a network protocol- Parameters:
urlString-Stringurl to check- Returns:
- TRUE if the URL defines a network protocol, FALSE otherwise
-
createFile
Allows to add a given array ofbyteas a cache file representing by theurl.- Parameters:
urlString- the URL to add to the cachebytes- the content of the cache file- Returns:
File
-
getDocumentFromCache
- Specified by:
getDocumentFromCachein interfaceeu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
-
post
- Specified by:
postin interfaceeu.europa.esig.dss.spi.client.http.DataLoader- Throws:
eu.europa.esig.dss.model.DSSException
-
get
- Specified by:
getin interfaceeu.europa.esig.dss.spi.client.http.DataLoader
-
setContentType
- Specified by:
setContentTypein interfaceeu.europa.esig.dss.spi.client.http.DataLoader
-