Interface AssetCache


  • public interface AssetCache
    Provides convenience methods for handling InputStreams from and temporary files for DAM asset renditions. A proper instance of an AssetCache can be retrieved via DamUtil.getAssetCache(). Every obtained instance needs to be release()d after use.

    The AssetCache might keep temporary files around for longer and reuse them in future AssetCache instances. This is transparent to the caller.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      ByteSource getByteSource​(Rendition rendition, boolean needFile)
      Get a ByteSource for the renction's content.
      java.io.File getFile​(Rendition rendition)
      Get an File with the content of the Asset rendition.
      java.io.InputStream getOriginalStream​(Asset asset, boolean needFile)
      Get an InputStream to the content of the original Asset rendition.
      java.io.InputStream getRenditionStream​(Asset asset, java.lang.String name, boolean needFile)
      Get an InputStream to the content of the Asset rendition with name.
      java.io.InputStream getStream​(Rendition rendition, boolean needFile)
      Get an InputStream to the content of the Asset rendition.
      void invalidateCache​(Asset asset)
      Notify the cache that an asset has been modified/deleted and that cached data is no longer valid
      void invalidateCache​(Rendition rendition)
      Notify the cache that an asset rendition has been modified/deleted and that cached data is no longer valid
      void release()
      Release this cache instance and cleanup all handed out streams and data.
    • Method Detail

      • getOriginalStream

        java.io.InputStream getOriginalStream​(Asset asset,
                                              boolean needFile)
                                       throws java.io.IOException
        Get an InputStream to the content of the original Asset rendition. The stream is automatically closed on release of this cache instance.
        Parameters:
        asset - the asset to get the original rendition for
        needFile - if a file based stream is preferred
        Returns:
        stream to original rendition content, closed on release
        Throws:
        java.io.IOException - if original rendition was not found
      • getRenditionStream

        java.io.InputStream getRenditionStream​(Asset asset,
                                               java.lang.String name,
                                               boolean needFile)
                                        throws java.io.IOException
        Get an InputStream to the content of the Asset rendition with name. The stream is automatically closed on release of this cache instance.
        Parameters:
        asset - the asset to get the original rendition for
        name - name of the rendition to get the content for
        needFile - if a file based stream is preferred
        Returns:
        stream to original rendition content, closed on release
        Throws:
        java.io.IOException - if original rendition was not found
      • getStream

        java.io.InputStream getStream​(Rendition rendition,
                                      boolean needFile)
                               throws java.io.IOException
        Get an InputStream to the content of the Asset rendition. The stream is automatically closed on release of this cache instance.
        Parameters:
        rendition - rendition to get the content for
        needFile - if a file based stream is preferred
        Returns:
        stream to original rendition content, closed on release
        Throws:
        java.io.IOException - if original rendition was not found
      • getFile

        java.io.File getFile​(Rendition rendition)
                      throws java.io.IOException
        Get an File with the content of the Asset rendition. The file is temporary and will be deleted on cache release (not necessarily the release of this cache instance).
        Parameters:
        rendition - rendition to get the content for
        Returns:
        stream to original rendition content, closed on release
        Throws:
        java.io.IOException - if original rendition was not found
      • getByteSource

        ByteSource getByteSource​(Rendition rendition,
                                 boolean needFile)
                          throws java.io.IOException
        Get a ByteSource for the renction's content. The source is automatically cleaned up on release of this cache instance.
        Parameters:
        rendition - rendition to get the content for
        needFile - if a file based stream is preferred
        Returns:
        stream to original rendition content, closed on release
        Throws:
        java.io.IOException - if original rendition was not found
      • invalidateCache

        void invalidateCache​(Asset asset)
        Notify the cache that an asset has been modified/deleted and that cached data is no longer valid
        Parameters:
        asset - asset that was modified/deleted.
      • invalidateCache

        void invalidateCache​(Rendition rendition)
        Notify the cache that an asset rendition has been modified/deleted and that cached data is no longer valid
        Parameters:
        rendition - rendition that was modified/deleted.
      • release

        void release()
        Release this cache instance and cleanup all handed out streams and data. Needs to be invoked at the end of cache use.