Package ch.autumo.beetroot.cache
Class FileCache
java.lang.Object
ch.autumo.beetroot.cache.FileCache
File cache.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longprotected static final org.slf4j.Logger -
Constructor Summary
ConstructorsConstructorDescriptionFile cache constructor.File cache constructor.File cache constructor.File cache constructor.File cache constructor.File cache constructor.FileCache(Path filePath, org.nanohttpd.protocols.http.content.ContentType contentType, boolean forcedCaching) File cache constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear cache if cached.org.nanohttpd.protocols.http.response.ResponseCreate response out of cached data.org.nanohttpd.protocols.http.response.ResponsecreateResponse(String mimeType) Create response out of cached data.booleangetData()Get data as stream from file or cache, depending of the buffer size.Return encoding.longGet file size.Get file full pat.longWhen was the file last modified or '-1' if it is a resource.Return mime type if anyGet text data.booleanIs it an archive?booleanisBinary()Is it a binary?booleanisCached()Cached?booleanIs it a resource (e.g. from JAR)?booleanisText()Is it a text file?
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
BUFFER_LIMIT
public static final long BUFFER_LIMIT
-
-
Constructor Details
-
FileCache
File cache constructor.- Parameters:
filePath- file pathmimeType- 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 pathcontentType- content header type, e.g. "text/html; charset=UTF-8"- Throws:
IOException- IO exception
-
FileCache
File cache constructor.- Parameters:
filePath- file pathmimeType- 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 pathcontentType- 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
File cache constructor. Resources are immutable, hence no re-caching will be done.- Parameters:
resourcePath- resource path- Throws:
IOException- IO exception
-
FileCache
File cache constructor. Resources are immutable, hence no re-caching will be done.- Parameters:
resourcePath- resource pathmimeType- 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 pathcontentType- content header type, e.g. "text/html; charset=UTF-8"- Throws:
IOException- IO exception
-
-
Method Details
-
getData
Get data as stream from file or cache, depending of the buffer size.- Returns:
- data stream
- Throws:
IOException- IO exception
-
getTextData
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
Create response out of cached data.- Returns:
- response
- Throws:
IOException- IO exception
-
getMimeType
Return mime type if any- Returns:
- mime type
-
getEncoding
Return encoding.- Returns:
- encoding
-
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
-