1 16 package org.apache.commons.vfs.cache; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystem; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.TreeMap ; 25 26 32 public class DefaultFilesCache extends AbstractFilesCache 33 { 34 private final Map filesystemCache = new HashMap (10); 35 36 public void putFile(final FileObject file) 37 { 38 Map files = getOrCreateFilesystemCache(file.getFileSystem()); 39 files.put(file.getName(), file); 40 } 41 42 public FileObject getFile(final FileSystem filesystem, final FileName name) 43 { 44 Map files = getOrCreateFilesystemCache(filesystem); 45 return (FileObject) files.get(name); 46 } 47 48 public void clear(FileSystem filesystem) 49 { 50 Map files = getOrCreateFilesystemCache(filesystem); 51 files.clear(); 52 } 53 54 protected Map getOrCreateFilesystemCache(FileSystem filesystem) 55 { 56 Map files = (Map ) filesystemCache.get(filesystem); 57 if (files == null) 58 { 59 files = new TreeMap (); 60 filesystemCache.put(filesystem, files); 61 } 62 63 return files; 64 } 65 66 public void close() 67 { 68 super.close(); 69 70 filesystemCache.clear(); 71 } 72 73 public void removeFile(FileSystem filesystem, FileName name) 74 { 75 Map files = getOrCreateFilesystemCache(filesystem); 76 files.remove(name); 77 } 78 79 public void touchFile(FileObject file) 80 { 81 } 82 } 83 | Popular Tags |