Package org.javlo.ztatic
Class FileCache
- java.lang.Object
-
- org.javlo.ztatic.FileCache
-
public class FileCache extends Object
this class is used for cache transformation of a file. The transformation is is identified from a key.- Author:
- pvandermaesen
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
void
clear(String context)
void
clearPDF(ContentContext ctx)
void
delete(ContentContext ctx, String fileName)
clear a file for all keys.void
deleteAllFile(String context, String fileName)
delete all files with this fileNameprotected File
getCacheDir()
File
getFile(String key, String fileName, long latestModificationDate)
InputStream
getFileInputStream(String key, String fileName, long latestModificationDate)
get a file in the cache, return null if file is'nt in the cache.File
getFileName(String key, String fileName)
static FileCache
getInstance(javax.servlet.ServletContext inApplication)
create a instance of FileCachelong
getLastModified(String key, String fileName)
get the last modified of a cached file.File
getPDFPage(ContentContext ctx, MenuElement page, boolean low)
Serializable
loadBean(String key)
static void
main(String[] args)
static void
saveFile(String fileName, InputStream in)
put file in cache. if this file exist old file is replace.OutputStream
saveFile(String key, String fileName)
put file in cache. if this file exist old file is replace.void
saveFile(String key, String fileName, InputStream in)
put file in cache. if this file exist old file is replace.TransactionFile
saveFileTransactional(String key, String fileName)
void
storeBean(String key, Serializable obj)
-
-
-
Field Detail
-
BASE_DIR
public static final String BASE_DIR
- See Also:
- Constant Field Values
-
PDF_LOCK
public static final Object PDF_LOCK
-
-
Method Detail
-
getInstance
public static final FileCache getInstance(javax.servlet.ServletContext inApplication)
create a instance of FileCache- Parameters:
inApplication
- the ServletContext- Returns:
- a instance in application scope.
-
saveFile
public void saveFile(String key, String fileName, InputStream in) throws IOException
put file in cache. if this file exist old file is replace.- Parameters:
key
- the key of the file.fileName
- the complete name of the file.in
- the data of the file.- Throws:
IOException
-
saveFile
public static void saveFile(String fileName, InputStream in) throws IOException
put file in cache. if this file exist old file is replace.- Parameters:
key
- the key of the file.fileName
- the complete name of the file.in
- the data of the file.- Throws:
IOException
-
saveFile
public OutputStream saveFile(String key, String fileName) throws IOException
put file in cache. if this file exist old file is replace.- Parameters:
key
- the key of the file.fileName
- the complete name of the file.- Returns:
- a outstream to the new file.
- Throws:
IOException
-
saveFileTransactional
public TransactionFile saveFileTransactional(String key, String fileName) throws IOException
- Throws:
IOException
-
getFileInputStream
public InputStream getFileInputStream(String key, String fileName, long latestModificationDate) throws IOException
get a file in the cache, return null if file is'nt in the cache.- Parameters:
key
- the key of cachingfileName
- the file name- Returns:
- a inputStream from file.
- Throws:
FileNotFoundException
IOException
-
getFile
public File getFile(String key, String fileName, long latestModificationDate) throws IOException
- Throws:
IOException
-
getLastModified
public long getLastModified(String key, String fileName) throws FileNotFoundException
get the last modified of a cached file.- Parameters:
key
- the key of cachingfileName
- the file name- Returns:
- a inputStream from file.
- Throws:
FileNotFoundException
-
getCacheDir
protected File getCacheDir()
-
delete
public void delete(ContentContext ctx, String fileName)
clear a file for all keys.- Parameters:
fileName
- a file name.
-
main
public static void main(String[] args)
-
deleteAllFile
public void deleteAllFile(String context, String fileName)
delete all files with this fileName- Parameters:
fileName
-context
- a context, if null all context is considered.
-
clear
public void clear(String context)
-
clear
public void clear()
-
storeBean
public void storeBean(String key, Serializable obj) throws IOException
- Throws:
IOException
-
loadBean
public Serializable loadBean(String key) throws ClassNotFoundException, IOException
- Throws:
ClassNotFoundException
IOException
-
clearPDF
public void clearPDF(ContentContext ctx) throws IOException
- Throws:
IOException
-
getPDFPage
public File getPDFPage(ContentContext ctx, MenuElement page, boolean low) throws ServiceException
- Throws:
ServiceException
-
-