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 voidclear()voidclear(String context)voidclearPDF(ContentContext ctx)voiddelete(ContentContext ctx, String fileName)clear a file for all keys.voiddeleteAllFile(String context, String fileName)delete all files with this fileNameprotected FilegetCacheDir()FilegetFile(String key, String fileName, long latestModificationDate)InputStreamgetFileInputStream(String key, String fileName, long latestModificationDate)get a file in the cache, return null if file is'nt in the cache.FilegetFileName(String key, String fileName)static FileCachegetInstance(javax.servlet.ServletContext inApplication)create a instance of FileCachelonggetLastModified(String key, String fileName)get the last modified of a cached file.FilegetPDFPage(ContentContext ctx, MenuElement page, boolean low)SerializableloadBean(String key)static voidmain(String[] args)static voidsaveFile(String fileName, InputStream in)put file in cache. if this file exist old file is replace.OutputStreamsaveFile(String key, String fileName)put file in cache. if this file exist old file is replace.voidsaveFile(String key, String fileName, InputStream in)put file in cache. if this file exist old file is replace.TransactionFilesaveFileTransactional(String key, String fileName)voidstoreBean(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:
FileNotFoundExceptionIOException
-
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:
ClassNotFoundExceptionIOException
-
clearPDF
public void clearPDF(ContentContext ctx) throws IOException
- Throws:
IOException
-
getPDFPage
public File getPDFPage(ContentContext ctx, MenuElement page, boolean low) throws ServiceException
- Throws:
ServiceException
-
-