Class FileCacheDataLoader

java.lang.Object
eu.europa.esig.dss.service.http.commons.FileCacheDataLoader
All Implemented Interfaces:
Serializable

public class FileCacheDataLoader extends Object
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:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor
    FileCacheDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader)
    Default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method allow indicating which resources must be ignored.
    void
    This method allow indicating if the resource must be obtained.
    createFile(String urlString, byte[] bytes)
    Allows to add a given array of byte as a cache file representing by the url.
    byte[]
    get(String url)
     
    byte[]
    get(String url, boolean refresh)
    Executes a GET request to the provided URL, with a forced cache refresh when defined
    eu.europa.esig.dss.spi.client.http.DataLoader.DataAndUrl
    get(List<String> urlStrings)
     
    eu.europa.esig.dss.spi.client.http.DataLoader
    Gets the dataloader
    eu.europa.esig.dss.model.DSSDocument
     
    eu.europa.esig.dss.model.DSSDocument
    getDocument(String url, boolean refresh)
    This method allows to download a DSSDocument from a specified url with a custom setting indicating whether the refresh of the document's cache shall be enforced, when applicable
    eu.europa.esig.dss.model.DSSDocument
     
    protected boolean
    Checks if the URL defines a network protocol
    byte[]
    post(String urlString, byte[] content)
     
    boolean
     
    void
    setCacheExpirationTime(long cacheExpirationTimeInMilliseconds)
    Sets the expiration time for the cached files in milliseconds.
    void
    setContentType(String contentType)
     
    void
    setDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader)
    Sets the data loader for a remote documents access (e.g. online)
    void
    setFileCacheDirectory(File fileCacheDirectory)
    This method allows to set the file cache directory.
    void
    Sets the ResourceLoader for an absolute path creation

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileCacheDataLoader

      public FileCacheDataLoader()
      Empty constructor
    • FileCacheDataLoader

      public FileCacheDataLoader(eu.europa.esig.dss.spi.client.http.DataLoader dataLoader)
      Default constructor
      Parameters:
      dataLoader - DataLoader to 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

      public void setFileCacheDirectory(File fileCacheDirectory)
      This method allows to set the file cache directory. If the cache folder does not exist then it's created.
      Parameters:
      fileCacheDirectory - File pointing 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

      public void setResourceLoader(ResourceLoader resourceLoader)
      Sets the ResourceLoader for an absolute path creation
      Parameters:
      resourceLoader - ResourceLoader
    • addToBeLoaded

      public void addToBeLoaded(String url)
      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

      public void addToBeIgnored(String urlString)
      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

      public byte[] get(String url, boolean refresh)
      Executes a GET request to the provided URL, with a forced cache refresh when defined
      Parameters:
      url - to access
      refresh - if true indicates that the cached data should be refreshed
      Returns:
      binaries of the extracted data object
    • get

      public byte[] get(String url) throws eu.europa.esig.dss.model.DSSException
      Throws:
      eu.europa.esig.dss.model.DSSException
    • getDocument

      public eu.europa.esig.dss.model.DSSDocument getDocument(String url, boolean refresh)
      This method allows to download a DSSDocument from a specified url with a custom setting indicating whether the refresh of the document's cache shall be enforced, when applicable
      Parameters:
      url - String remote location of the document to download
      refresh - indicates whether the refresh of the cached document shall be enforced
      Returns:
      DSSDocument
    • getDocument

      public eu.europa.esig.dss.model.DSSDocument getDocument(String url)
    • remove

      public boolean remove(String url)
    • isNetworkProtocol

      protected boolean isNetworkProtocol(String urlString)
      Checks if the URL defines a network protocol
      Parameters:
      urlString - String url to check
      Returns:
      TRUE if the URL defines a network protocol, FALSE otherwise
    • createFile

      public File createFile(String urlString, byte[] bytes)
      Allows to add a given array of byte as a cache file representing by the url.
      Parameters:
      urlString - the URL to add to the cache
      bytes - the content of the cache file
      Returns:
      File
    • getDocumentFromCache

      public eu.europa.esig.dss.model.DSSDocument getDocumentFromCache(String url)
    • post

      public byte[] post(String urlString, byte[] content) throws eu.europa.esig.dss.model.DSSException
      Throws:
      eu.europa.esig.dss.model.DSSException
    • get

      public eu.europa.esig.dss.spi.client.http.DataLoader.DataAndUrl get(List<String> urlStrings)
    • setContentType

      public void setContentType(String contentType)