Java Reference
In-Depth Information
L ISTING 6.2 Continued
}
}
/**
* check if a file is in cache
*/
protected boolean isCached(String item){
File file = new File(CACHE_DIR);
if(file.exists() && file.isDirectory()) {
File[] dirContent = file.listFiles();
for(int i = 0; i < dirContent.length; i++) {
if(dirContent[i].getName().equals(item))
return true;
}//-for
}
return false;
}
/**
* It stores a file in the local cache
*/
protected void cache(String name, byte[] b) {
try {
FileOutputStream fos = new FileOutputStream(CACHE_DIR+name);
fos.write(b);
fos.close();
} catch (IOException exce) {
System.out.println(“ApplicationHelper- cache(“+name+”) “+exce);
}
System.out.println(“ApplicationHelper- saved in cache: “+name);
}
/**
* It gets a file from the cache directory
* @return a File
*/
public File getCachedFile(String filename){
File file = null;
try {
file = new File(CACHE_DIR, filename);
} catch (Exception e) {
System.out.println(“ApplicationHelper- getFile(): “ + e);
}
return file;
}
Search WWH ::




Custom Search