Class FileCache

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

public class FileCache extends Object
File cache.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • BUFFER_LIMIT

      public static final long 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 - IO exception
    • FileCache

      public FileCache(Path filePath, org.nanohttpd.protocols.http.content.ContentType contentType) throws IOException
      File cache constructor.
      Parameters:
      filePath - file path
      contentType - content header type, e.g. "text/html; charset=UTF-8"
      Throws:
      IOException - IO exception
    • 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? Force caching breaks the file size limit, but not the cache size limit!
      Throws:
      IOException - IO exception
    • FileCache

      public FileCache(Path filePath, org.nanohttpd.protocols.http.content.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? Force caching breaks the file size limit, but not the cache size limit!
      Throws:
      IOException - IO exception
    • FileCache

      public FileCache(String resourcePath) throws IOException
      File cache constructor. Resources are immutable, hence no re-caching will be done.
      Parameters:
      resourcePath - resource path
      Throws:
      IOException - IO exception
    • FileCache

      public FileCache(String resourcePath, String mimeType) throws IOException
      File cache constructor. Resources are immutable, hence no re-caching will be done.
      Parameters:
      resourcePath - resource path
      mimeType - mime type, e.g. "text/html"
      Throws:
      IOException - IO exception
    • FileCache

      public FileCache(String resourcePath, org.nanohttpd.protocols.http.content.ContentType contentType) throws IOException
      File cache constructor. Resources are immutable, hence no re-caching will be done.
      Parameters:
      resourcePath - resource path
      contentType - content header type, e.g. "text/html; charset=UTF-8"
      Throws:
      IOException - IO exception
  • 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 - IO exception
    • getTextData

      public String getTextData() throws IOException
      Get text data.
      Returns:
      cached data as text or null
      Throws:
      IOException - IO exception
    • createResponse

      public org.nanohttpd.protocols.http.response.Response createResponse(String mimeType) throws IOException
      Create response out of cached data.
      Parameters:
      mimeType - mime type
      Returns:
      response
      Throws:
      IOException - IO exception
    • createResponse

      public org.nanohttpd.protocols.http.response.Response createResponse() throws IOException
      Create response out of cached data.
      Returns:
      response
      Throws:
      IOException - IO exception
    • 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
    • getFileSize

      public long getFileSize()
      Get file size.
      Returns:
      file size
    • isArchive

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

      public boolean isBinary()
      Is it a binary? Resources are immutable, hence no re-caching will be done.
      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