Back to project page WebImageView.
The source code is released under:
MIT License
If you think the Android project WebImageView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.rsv.cache; /* www .j a va 2 s . c om*/ import java.io.File; import com.rsv.utils.FileUtils; abstract class BaseFileCache { protected final File cacheDir; public BaseFileCache(final File cacheDir) { if (!cacheDir.exists()) { throw new IllegalArgumentException(cacheDir + " not exists"); } if (!cacheDir.canWrite()) { throw new IllegalArgumentException(cacheDir + " not writable"); } this.cacheDir = cacheDir; } /** * @param key * the identify string, will be converted to a file name * @param file * the original file * * @return the cached file */ public File put(String key, File file) { File tFile = getTargetFile(key); if (!file.equals(tFile)) { // well, this file is not the target cache file FileUtils.copyFile(file, tFile); } return tFile; } /** * delete the file * * @param key */ public void remove(String key) { File file = this.get(key); if (file != null) { file.delete(); } } /** * Given a string key, return the targeted cache file * * @param key * @return */ public File getTargetFile(String key) { return new File(cacheDir, keyToFileName(key)); } public File get(String key) { File file = this.getTargetFile(key); if (!file.exists()) return null; return file; } /** * Remote all files in this cacheDir */ public void clear() { File[] files = cacheDir.listFiles(); if (files != null) { for (File f : files) { f.delete(); } } } protected File getCacheDir() { return cacheDir; } protected String keyToFileName(String key) { return "c" + Integer.toHexString(key.hashCode()); } }