public class FileCacheByPath
extends java.lang.Object
FileCacheByPath is that files are stored and can be later retrieved from their original path.
For example:
File cacheDir = ... // some directory.
FileCacheByPath cache = new FileCacheByPath(cacheDir);
File a = new File(...); // some file in the filesystem.
cache.add(a);
// Modify file "a".
File b = cache.get(a); // "b" will be a different file whose
// contents are those of "a" before
// being modified.
A custom API for zip files (add(ZipCentralDirectory) allows to only store a zip file's
Central Directory Record as this is generally only what is needed from the cache.| Constructor and Description |
|---|
FileCacheByPath(java.io.File directory)
Creates a new cache.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.io.File f)
Adds a file to the cache, replacing any file that had the exact same absolute path.
|
void |
add(com.android.builder.files.ZipCentralDirectory centralDirectory)
Adds a file to the cache, replacing any file that had the exact same absolute path.
|
void |
clear()
Clears the cache.
|
java.io.File |
get(java.io.File f)
Obtains the cached file corresponding to the file with the given path.
|
void |
remove(java.io.File f)
Removes any cached version of the given path.
|
public FileCacheByPath(@NonNull
java.io.File directory)
directory - the directory where the cache is storedpublic void add(@NonNull
java.io.File f)
throws java.io.IOException
f - the file to addjava.io.IOException - failed to copy the file into the cachepublic void add(@NonNull
com.android.builder.files.ZipCentralDirectory centralDirectory)
throws java.io.IOException
centralDirectory - the file to addjava.io.IOException - failed to copy the file into the cache@Nullable
public java.io.File get(@NonNull
java.io.File f)
f - the pathnull if there is no file in the cache that corresponds to
the given filepublic void remove(@NonNull
java.io.File f)
throws java.io.IOException
f - the pathjava.io.IOException - failed to remove the filepublic void clear()
throws java.io.IOException
java.io.IOException - failed to clear the cache