import java.io.*; import java.net.*; import java.util.*; public class Cache { Hashtable htable; String cachePath = null, tmp=null; BufferedReader f=null; StringTokenizer z; String tablefname="tableFile.txt"; public Cache() { htable=new Hashtable(); try { // read tableFile.txt and add to hashtable File ff=new File(tablefname); if(ff.exists()) { f=new BufferedReader(new FileReader(tablefname)); String line=f.readLine(); String rawurl="", name=""; while(line!=null) { z=new StringTokenizer(line); rawurl=z.nextToken(); name=z.nextToken(); AddToTable(rawurl, name); line=f.readLine(); } }// if(ff.exists()) // Create directory for caching File cacheDir = new File("Cache"); cacheDir.mkdirs(); cachePath = cacheDir.getAbsolutePath(); System.out.println("cachePath: " + cachePath); f.close(); }//try catch(Exception e) { System.out.println(e);} } public String getcachePath() { return cachePath + File.separatorChar; // --> Cache/ } public boolean IsCached(String rawUrl) { // Search in hash table if (htable.get(rawUrl) != null) { System.out.println("**"+ htable.get(rawUrl)+" is cached."); return true; } return false; } public String getFilename(String rawUrl) { if (htable.get(rawUrl) != null) return htable.get(rawUrl).toString(); else return ""; } public synchronized void AddToTable(String rawUrl, String fname) { htable.put(rawUrl, fname); } }// Cache