|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openstreetmap.josm.io.CacheFiles
public class CacheFiles
Use this class if you want to cache a lot of files that shouldn't be kept in memory. You can specify how much data should be stored and after which date the files should be expired. This works on a last-access basis, so files get deleted after they haven't been used for x days. You can turn this off by calling setUpdateModTime(false). Files get deleted on a first-in-first-out basis.
| Field Summary | |
|---|---|
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 Summary | |
|---|---|
CacheFiles(java.lang.String ident)
Creates a new cache class. |
|
CacheFiles(java.lang.String ident,
boolean isPlugin)
|
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
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
| Constructor Detail |
|---|
public CacheFiles(java.lang.String ident)
ident -
public CacheFiles(java.lang.String ident,
boolean isPlugin)
| Method Detail |
|---|
public byte[] getData(java.lang.String ident)
ident -
public void saveData(java.lang.String ident,
byte[] data)
ident - data - public java.awt.image.BufferedImage getImg(java.lang.String ident)
ident - Identifier
public void saveImg(java.lang.String ident,
java.awt.image.BufferedImage image)
ident - image -
public void setExpire(int amount,
boolean force)
amount - of time in secondsforce - will also write it to the preferences
public void setMaxSize(int amount,
boolean force)
amount - in Megabytesforce - will also write it to the preferencespublic void setUpdateModTime(boolean to)
to - public 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 - ending -
private java.io.File getPath(java.lang.String ident)
ident - ending -
private boolean isExpired(java.io.File file)
file -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||