public class CacheFiles extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
CLEAN_ALL |
static int |
CLEAN_BY_DATE |
static int |
CLEAN_SMALL_FILES |
private static int |
CLEANUP_INTERVAL |
private static int |
CLEANUP_TRESHOLD |
private java.io.File |
dir |
private boolean |
enabled |
private long |
expire |
static int |
EXPIRE_DAILY |
static int |
EXPIRE_MONTHLY |
static int |
EXPIRE_NEVER
Common expirey dates
|
static int |
EXPIRE_WEEKLY |
private java.lang.String |
ident |
private long |
maxsize |
private boolean |
updateModTime |
private int |
writes |
Constructor and Description |
---|
CacheFiles(java.lang.String ident)
Creates a new cache class.
|
CacheFiles(java.lang.String ident,
boolean isPlugin)
Creates a new cache class.
|
Modifier and Type | Method and Description |
---|---|
void |
checkCleanUp()
Checks if a clean up is needed and will do so if necessary
|
void |
cleanUp()
Performs a default clean up with the set values (deletes oldest files first)
|
void |
customCleanUp(int type,
int size)
Performs a non-default, specified clean up
|
byte[] |
getData(java.lang.String ident)
Loads the data for the given ident as an byte array.
|
private long |
getDirSize()
Calculates the size of the directory
|
java.awt.image.BufferedImage |
getImg(java.lang.String ident)
Loads the data for the given ident as an image.
|
private java.io.File |
getPath(java.lang.String ident)
Gets file path for ident
|
private java.io.File |
getPath(java.lang.String ident,
java.lang.String ending)
Gets file path for ident with customizable file-ending
|
private static java.lang.String |
getUniqueFilename(java.lang.String ident)
Returns a short and unique file name for a given long identifier
|
private boolean |
isExpired(java.io.File file)
Checks whether a given file is expired
|
void |
saveData(java.lang.String ident,
byte[] data)
Writes an byte-array to disk
|
void |
saveImg(java.lang.String ident,
java.awt.image.BufferedImage image)
Saves a given image and ident to the cache
|
void |
setExpire(int amount,
boolean force)
Sets the amount of time data is stored before it gets expired
|
void |
setMaxSize(int amount,
boolean force)
Sets the amount of data stored in the cache
|
void |
setUpdateModTime(boolean to)
Call this with
true to update the last modification time when a file it is read. |
public static final int EXPIRE_NEVER
public static final int EXPIRE_DAILY
public static final int EXPIRE_WEEKLY
public static final int EXPIRE_MONTHLY
private final java.io.File dir
private final java.lang.String ident
private final boolean enabled
private long expire
private long maxsize
private boolean updateModTime
private static final int CLEANUP_TRESHOLD
private static final int CLEANUP_INTERVAL
private int writes
public static final int CLEAN_ALL
public static final int CLEAN_SMALL_FILES
public static final int CLEAN_BY_DATE
public CacheFiles(java.lang.String ident)
true
.ident
- cache identifierpublic CacheFiles(java.lang.String ident, boolean isPlugin)
ident
- cache identifierisPlugin
- Whether this is a plugin or not (changes cache path)public byte[] getData(java.lang.String ident)
ident
- cache identifierpublic void saveData(java.lang.String ident, byte[] data)
ident
- cache identifierdata
- data to storepublic java.awt.image.BufferedImage getImg(java.lang.String ident)
ident
- cache identifierpublic void saveImg(java.lang.String ident, java.awt.image.BufferedImage image)
ident
- cache identifierimage
- imaga data for storagepublic void setExpire(int amount, boolean force)
amount
- of time in secondsforce
- will also write it to the preferencespublic void setMaxSize(int amount, boolean force)
amount
- in Megabytesforce
- will also write it to the preferencespublic void setUpdateModTime(boolean to)
true
to update the last modification time when a file it is read.
Call this with false
to not update the last modification time when a file is read.to
- update statepublic void checkCleanUp()
public void cleanUp()
public void customCleanUp(int type, int size)
type
- any of the CLEAN_XX constants.size
- for CLEAN_SMALL_FILES: deletes all files smaller than (size) bytesprivate long getDirSize()
private static java.lang.String getUniqueFilename(java.lang.String ident)
private java.io.File getPath(java.lang.String ident, java.lang.String ending)
ident
- cache identifierending
- file extensionprivate java.io.File getPath(java.lang.String ident)
ident
- cache identifierprivate boolean isExpired(java.io.File file)
file
- file description structure