Class ShaCache


  • public class ShaCache
    extends java.lang.Object
    Provide a standardized cache based on the SHA-1 of a file.
    • Constructor Summary

      Constructors 
      Constructor Description
      ShaCache​(java.io.File root)
      Create a SHA-1 cache on a directory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.File getFile​(java.lang.String sha, ShaSource... sources)
      Small variation on the cache that returns a file instead of a stream
      java.io.File getRoot()
      Get the root to the cache
      java.io.InputStream getStream​(java.lang.String sha, ShaSource... sources)
      Return a stream that is associated with a SHA.
      void purge()
      Clean the cache
      • Methods inherited from class java.lang.Object

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

      • ShaCache

        public ShaCache​(java.io.File root)
        Create a SHA-1 cache on a directory.
        Parameters:
        root - the directory
    • Method Detail

      • getStream

        public java.io.InputStream getStream​(java.lang.String sha,
                                             ShaSource... sources)
                                      throws java.lang.Exception
        Return a stream that is associated with a SHA. If the SHA is not in the local cache, the given sources parameter can specify a way to get the content.
        Parameters:
        sha - the sha
        sources - objects that can retrieve the original data
        Returns:
        the stream or null if not found.
        Throws:
        java.lang.Exception
      • getFile

        public java.io.File getFile​(java.lang.String sha,
                                    ShaSource... sources)
                             throws java.lang.Exception
        Small variation on the cache that returns a file instead of a stream
        Parameters:
        sha - the SHA-1
        sources - the inputs
        Returns:
        a file or null
        Throws:
        java.lang.Exception
      • purge

        public void purge()
                   throws java.lang.Exception
        Clean the cache
        Throws:
        java.lang.Exception
      • getRoot

        public java.io.File getRoot()
        Get the root to the cache