Class FileCacheDataLoader
java.lang.Object
eu.europa.esig.dss.service.http.commons.FileCacheDataLoader
- All Implemented Interfaces:
DataLoader,DSSCacheFileLoader,DSSFileLoader,Serializable
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
DataLoader.DataAndUrl -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructorFileCacheDataLoader(DataLoader dataLoader) Default constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToBeIgnored(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.createFile(String urlString, byte[] bytes) Allows to add a given array ofbyteas a cache file representing by theurl.byte[]Execute a HTTP GET operation.byte[]Executes a GET request to the provided URL, with a forced cacherefreshwhen definedExecute a HTTP GET operation.Gets the dataloadergetDocument(String url) Returns DSSDocument from the provided urlgetDocument(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 applicableAllows to load a document for a given url from the cache folder.protected booleanisNetworkProtocol(String urlString) Checks if the URL defines a network protocolbyte[]loadFileFromCache(String urlString) Deprecated.since DSS 6.1.byte[]Executes a HTTP POST operationbooleanRemoves the file from cache with the given urlvoidsetCacheExpirationTime(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) 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
Default constructor- Parameters:
dataLoader-DataLoaderto use for remote access (e.g. online)
-
-
Method Details
-
getDataLoader
-
setDataLoader
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 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 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 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
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
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
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- Throws:
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 interfaceDSSCacheFileLoader- Parameters:
url-Stringremote location of the document to downloadrefresh- indicates whether the refresh of the cached document shall be enforced- Returns:
DSSDocument
-
getDocument
Description copied from interface:DSSFileLoaderReturns DSSDocument from the provided url- Specified by:
getDocumentin interfaceDSSFileLoader- Parameters:
url-Stringurl of the document to obtain- Returns:
DSSDocumentretrieved document
-
remove
Description copied from interface:DSSCacheFileLoaderRemoves the file from cache with the given url- Specified by:
removein interfaceDSSCacheFileLoader- Specified by:
removein interfaceDSSFileLoader- Parameters:
url-Stringurl of the remote file location (the same what was used on file saving)- Returns:
- TRUE when file was successfully deleted, FALSE otherwise
-
isNetworkProtocol
-
createFile
-
loadFileFromCache
Deprecated.since DSS 6.1. Please use#getDocumentFromCachemethod insteadAllows to load the file for a given file name from the cache folder.- Parameters:
urlString-Stringurl- Returns:
- the content of the file or
nullif the file does not exist - Throws:
DSSException- in case if the file does not exist in the cache
-
getDocumentFromCache
Description copied from interface:DSSCacheFileLoaderAllows to load a document for a given url from the cache folder. If the document is not found in the cache, returns NULL.- Specified by:
getDocumentFromCachein interfaceDSSCacheFileLoader- Parameters:
url-Stringurl of the file- Returns:
DSSDocumentor NULL if the file does not exist
-
post
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
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
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
-