Class FileCache

java.lang.Object
ch.autumo.commons.cache.FileCache

public class FileCache extends Object
File cache.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
      Logger.
    • BUFFER_LIMIT

      public static final long BUFFER_LIMIT
      Buffer limit.
  • Constructor Details

    • FileCache

      public FileCache(Path filePath, String mimeType) throws IOException
      File cache constructor.
      Parameters:
      filePath - file path
      mimeType - mime type, e.g. "text/html"
      Throws:
      IOException - if file cache cannot be created
    • FileCache

      public FileCache(Path filePath, ContentType contentType) throws IOException
      File cache constructor.
      Parameters:
      filePath - file path
      contentType - content header type, e.g. "text/html; charset=UTF-8"
      Throws:
      IOException - if file cache cannot be created
    • FileCache

      public FileCache(Path filePath, String mimeType, boolean forcedCaching) throws IOException
      File cache constructor.
      Parameters:
      filePath - file path
      mimeType - mime type, e.g. "text/html"
      forcedCaching - force caching?
      Throws:
      IOException - if file cache cannot be created
    • FileCache

      public FileCache(Path filePath, ContentType contentType, boolean forcedCaching) throws IOException
      File cache constructor.
      Parameters:
      filePath - file path
      contentType - content header type, e.g. "text/html; charset=UTF-8"
      forcedCaching - force caching?
      Throws:
      IOException - if file cache cannot be created
    • FileCache

      public FileCache(String resourcePath) throws IOException
      File cache constructor.
      Parameters:
      resourcePath - resource path
      Throws:
      IOException - if file cache cannot be created
    • FileCache

      public FileCache(String resourcePath, String mimeType) throws IOException
      File cache constructor.
      Parameters:
      resourcePath - resource path
      mimeType - mime type, e.g. "text/html"
      Throws:
      IOException - if file cache cannot be created
    • FileCache

      public FileCache(String resourcePath, ContentType contentType) throws IOException
      File cache constructor.
      Parameters:
      resourcePath - resource path
      contentType - content header type, e.g. "text/html; charset=UTF-8"
      Throws:
      IOException - if file cache cannot be created
  • Method Details

    • getData

      public InputStream getData() throws IOException
      Get data as stream from file or cache, depending of the buffer size.
      Returns:
      data stream
      Throws:
      IOException - if data cannot be acquired from cache
    • getTextData

      public String getTextData() throws IOException
      Get text data.
      Returns:
      cached data as text or null
      Throws:
      IOException - if text data cannot be acquired from cache
    • getMimeType

      public String getMimeType()
      Return mime type if any
      Returns:
      mime type
    • getEncoding

      public String getEncoding()
      Return encoding.
      Returns:
      encoding
    • getFullPath

      public String getFullPath()
      Get file full pat.
      Returns:
      file path
    • isCached

      public boolean isCached()
      Cached?
      Returns:
      true if so
    • getLastModified

      public long getLastModified()
      When was the file last modified or '-1' if it is a resource.
      Returns:
      last modification of file or -1
    • isArchive

      public boolean isArchive()
      Is it an archive?
      Returns:
      is it an archive
    • isBinary

      public boolean isBinary()
      Is it a binary?
      Returns:
      is it a binary
    • isText

      public boolean isText()
      Is it a text file?
      Returns:
      is it a text file
    • isResource

      public boolean isResource()
      Is it a resource (e.g. from JAR)?
      Returns:
      is it a resoruce
    • clear

      public void clear()
      Clear cache if cached.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object