alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javacvs.caching;

/**
 *
 * @author  mkleint
 * @version 
 */
import java.io.*;
import java.util.*;
import org.netbeans.modules.vcscore.cache.*;
import org.netbeans.modules.javacvs.commands.JavaCvsStatusManager;
import org.netbeans.modules.javacvs.*;
import org.netbeans.modules.javacvs.commands.*;



public class CvsCacheDir extends CacheDir {
    
//    protected String status;
    
    private static final String CACHE_FILENAME = File.separator + "CVS" + File.separator + "netbeans.cache"; // NOI18N
    private static final String CACHE_NEW_FILENAME = File.separator + "CVS" + File.separator + "javacvs.cache"; // NOI18N
    private static final String CACHE_VIRTUAL_FILENAME = File.separator + "CVS" + File.separator + "javacvs.virtuals"; // NOI18N

    
    private static FileFilter cvsFilter =  new FileFilter() {
              public boolean accept(File f) {
                 if (f.isDirectory() && f.getName().equalsIgnoreCase("CVS")) return true; // NOI18N
                 return false;
              }
    };

    //private boolean firstTimer;
    
    /** Creates new CvsCacheDir */
    public CvsCacheDir(String cacheName, File dirFile) {
        this(cacheName, dirFile, new CvsCacheFile.CvsPersistentData(true));
    }
    
    CvsCacheDir(String cacheName, File dirFile, CacheFile.PersistentData data) {
        super(cacheName, dirFile, data);
        File cvsSubDir = new File(dirFile,"CVS"); // NOI18N
        if (!cvsSubDir.exists()) {
          setLocal(true);
          setStatus(JavaCvsStatusManager.LOCAL);
          //firstTimer = false;
        } else {
           setLocal(false);
           setStatus(" "); // NOI18N
           //firstTimer = true;
        }
    }
    
    /*
    void setFirstTimer(boolean first) {
        firstTimer = first;
    }
    
    boolean isFirstTimer() {
        return firstTimer;
    }
     */

    protected CacheFile createChildFromData(CacheFile.PersistentData data) {
        CacheFile file;
        if (data.isDirectory()) {
            file = new CvsCacheDir(getCacheName(), new File(dirFile, data.getName()), data);
        } else {
            file = new CvsCacheFile(getCacheName(), data);
        }
        return file;
    }
    
    public synchronized void populateWithLocal(Object locker) {
        if (getAppliedLevel() >= CacheHandler.STRAT_LOCAL) {
            repopulate();
        } else {
//           System.out.println("populateWithLocal()=" + dirFile.getAbsolutePath());
            //        E.err("populateWithLocal()" + dirFile.getAbsolutePath());
            File[] subFiles = dirFile.listFiles();
            if (subFiles == null) {
                return;
            }
            CacheHandler handler = CacheHandler.getInstance();
            CacheFile file;
            for (int index = 0; index < subFiles.length; index++) {
                File oneFile = subFiles[index];
                if (oneFile == null) continue;
                if (oneFile.isDirectory()) {
                    if (getSubDir(oneFile.getName()) == null) {
                        file = new CvsCacheDir(getCacheObject().getId(), oneFile);
                        addChildDir((CacheDir) file, false);
                        handler.addCacheLocker(locker, file);
                    }
                } else {
                    if (getFile(oneFile.getName()) == null) {
                        file = new CvsCacheFile(getCacheObject().getId(), oneFile.getName());
                        this.addFile(file, false);
                        handler.addCacheLocker(locker, file);
                    }
                }
            }
            setAppliedLevel(CacheHandler.STRAT_LOCAL);
        }
        readVirtualsFromDisk(); // in order to have the disk cache added during children() calls.
    }
    
    public synchronized void repopulate() {
// System.out.println("repopulate()=" + dirFile.getAbsolutePath());
        if (!dirFile.exists()) {
            removeAll(true);
            if (getParent() != null) {
                getParent().removeChildDir(getName(), true);
            }
            return;
        }
        File[] cvsDir = dirFile.listFiles(cvsFilter);
        setLocal(cvsDir.length == 0); 
        File[] subFiles = dirFile.listFiles();
        CacheDir[] cacheDirs = getSubDirs();
        // remove wrong directories..
        for (int index = 0; index < cacheDirs.length; index++) {
           CacheDir dir = cacheDirs[index];
           if (dir == null) continue;
           File found = null;
           for (int ind2 = 0; ind2 < subFiles.length; ind2++) {
               if (subFiles[ind2] == null) continue;
               if (subFiles[ind2].getName().equals(dir.getName())) {
                   found = subFiles[ind2];
                   subFiles[ind2] = null;
                   break;
               }
           }
           if (found == null) {
               removeChildDir(dir.getName(), false);
           } else 
               if (!found.isDirectory()) {
                   removeChildDir(dir.getName(), false);
               }
        }
        // remove wrong files..
        CacheFile[] cacheFiles = getFiles();
        for (int index = 0; index < cacheFiles.length; index++) {
           CacheFile cfile = cacheFiles[index];
//           System.out.println("cFile=" + cfile.getName());
           if (cfile == null) continue;
           File found = null;
           for (int ind2 = 0; ind2 < subFiles.length; ind2++) {
               if (subFiles[ind2] == null) continue;
               if (subFiles[ind2].getName().equals(cfile.getName())) {
                   found = subFiles[ind2];
                   subFiles[ind2] = null;
                   break;
               }
           }
           if (found == null) {
               // the cache file is not present locally..
//               System.out.println("cFile=" + cfile.getName() + " not found");
//               System.out.println("islocal=" + isLocal());
//               System.out.println("status =" + cfile.getStatus());
               if (isLocal()) {
                   removeFile(cfile.getName(), false);
               } else {
                   String status = cfile.getStatus();
                   if (status == null) {
//                       cfile.setStatus(JavaCvsStatusManager.UNKNOWN);
                   } else
                   if (status.equals(JavaCvsStatusManager.LOCALLY_REMOVED)) {

                       // keep it.
//                       removeFile(cfile.getName(), false);
                   } 
                   else if (status.equals(JavaCvsStatusManager.LOCAL) || 
                            status.equals(JavaCvsStatusManager.UNKNOWN) ||
                            status.equals(JavaCvsStatusManager.LOCALLY_ADDED)) {
                       removeFile(cfile.getName(), false);
                   } 
                   else {
                       cfile.setStatus(JavaCvsStatusManager.NEEDS_CHECKOUT);
                   }
               }
           } else {
               if (isLocal() &&  
                   (!cfile.getStatus().equals(JavaCvsStatusManager.LOCAL))) 
               {
                   removeFile(cfile.getName(), false);
               }
           }
        }
        //now add the ones that were not present.. 
        for (int ind3 = 0; ind3 < subFiles.length; ind3++) {
            if (subFiles[ind3] == null) continue;
            File file = subFiles[ind3];
            if (!file.exists()) continue;
            if (file.isDirectory()) {
                addChildDir(new CvsCacheDir(JavaCvsCache.JAVA_CACHE_NAME, file), false);
            } else {
                addFile(new CvsCacheFile(JavaCvsCache.JAVA_CACHE_NAME, file.getName()), false);
            }
        }
    }
    /** returns the name of the directory
     */
    public String getName() {
        if (dirFile.getParentFile() == null) {
            return dirFile.getAbsolutePath();
        }
        return dirFile.getName(); // return short name, just name of file..
        //        return dirName;
    }    
   
    public void simpleWriteToDisk() {
//        System.out.println("writing " + getAbsolutePath());
        BufferedWriter out = null;
        BufferedWriter virtOut = null;
        try{
            virtOut = new BufferedWriter(new FileWriter(getCacheVirtualsFileName())); // NOI18N
            // files get written first
            CacheFile[] files = getFiles();
            for(int i = 0; i < files.length; i++) {
                CvsCacheFile file = (CvsCacheFile) files[i];
                if (file != null) {
                    File virtCheck = new File(file.getAbsolutePath());
                    if (!virtCheck.exists()) {
                        virtOut.write(file.getName());
                        virtOut.newLine();
                    }
                }
            }
            virtOut.flush();
            
            out = new BufferedWriter(new FileWriter(getCacheNewFileName())); // NOI18N
            // files get written first
            for(int i = 0; i < files.length; i++) {
                CvsCacheFile file = (CvsCacheFile) files[i];
                if (file != null && !file.getStatus().equals(JavaCvsStatusManager.LOCAL)) {
                    out.write(((CvsCacheFile.CvsPersistentData) file.getPersistentData()).writeLineToDisk());
                    out.newLine();
                }
            }
            out.flush();
            setModifiedContent(false);
        }
        catch (IOException e){
            //            E.err(e,"writeDirToDiskCache() failed for "+getName()); // NOI18N
        } finally {
            try {
                if (out != null) out.close();
                if (virtOut != null) virtOut.close();
                File oldContent = new File(getCacheFileName());
                if (oldContent.exists()) {
                    oldContent.delete();
                }
            } catch (IOException e) {
                //                E.err(e,"writeDirToDiskCache() failed for "+getName()); // NOI18N
            }
        }
    }
        
    
    public synchronized void writeToDisk() {
        //if (!isComplete()) return;
        File[] cvsDir = dirFile.listFiles(cvsFilter);
        if (cvsDir == null || cvsDir.length == 0)  return; // it's not a CVS dir.. nothing is written..
        File netbeansFile = new File(getCacheNewFileName());

        // even if this directory is not modified , the cache file is written down 
        // .. BUT only when if already doesn't exist.. (we don't want to overwrite not-read files, do we? :)
        // useful to create cache files and populate the structure with netbeans.cache files
        //if ((!this.isModifiedContent()) && (netbeansFile.exists())) return; // nothing to save.. noting changed (status of files might change even if the content is not modified!)
        // Do not write down directories that hasn't been at least locally read (that would write empty dir.
        // Also do not write if the file netbeans.cache exists AND wasn't read.
        if ((!netbeansFile.exists() && (getAppliedLevel() < CacheHandler.STRAT_DISK))
            || (getAppliedLevel() < CacheHandler.STRAT_DISK)) return;
        simpleWriteToDisk();
    }
    
    private boolean readFromDisk_Old() {
        //synchronized removed since it's only called from readFromDisk()
        boolean isOk = false;
        File cacheFile=new File(getCacheFileName()); // the actual netbeans.cache file
//        System.out.println("readFromDisk()=" + this.getAbsolutePath());
        if(cacheFile.exists() && cacheFile.canRead() ){
//            System.out.println("reading old=" + getAbsolutePath());
            BufferedReader in = null;
            try{
               in = new BufferedReader(new FileReader(cacheFile));
                String line=null;
                LinkedList processedList = new LinkedList();
                //setFirstTimer(false);
                //boolean reload = false;
                while ((line=in.readLine())!=null ){
                    CacheFile file = CvsCacheFile.readFileCache(line, this);
                    /*
                    if (!reload) {
                        reload = isFirstTimer();
                    }
                     */
                    if (file != null) {
                        if (file instanceof CvsCacheFile) {
                            processedList.add(file);
                        }
                    }
                }
                in.close();
                isOk= true;
                CacheFile[] files = getFiles();
                LinkedList toBeRemoved = new LinkedList();
                for(int i = 0; i < files.length; i++) {
                    CvsCacheFile fil = (CvsCacheFile) files[i];
                    if (!processedList.contains(fil)) {
                        File f = new File(fil.getAbsolutePath());
                        if (!f.exists()) {
//                            System.out.println("in cvscachedir.. removing=" + f.getAbsolutePath());
                            toBeRemoved.add(fil);
                        }
                    }
                }
                if (toBeRemoved.size() > 0) {
                    Iterator it2 = toBeRemoved.iterator();
                    while (it2.hasNext()) {
                        removeFile(((CacheFile)it2.next()).getName(), false);
                    }
                }
                setAppliedLevel(CacheHandler.STRAT_DISK);
/* currently should not happen since we load the disk on  children() call..
                  if (reload) {
                    org.openide.util.RequestProcessor.postRequest(new Runnable() {
                        public void run() {
//                            System.out.println("started a refreshing thread for=" + CvsCacheDir.this.getAbsolutePath());
                            CvsCacheDir.this.getCacheObject().fireCacheHandlerEvent(FileSystemCache.EVENT_ADD, CvsCacheDir.this);
                        }
                    });
 
                }
 */
                return isOk;
            }catch (IOException e){
//                E.err(e,"readDirFromDiskCache() failed"); // NOI18N
            } finally {
                if (in != null) { 
                    try {in.close();
                    } catch (IOException exc) {}
                    in = null;
                }
            }
        } else {
            // if not exists, let's assume we applied the level
            setAppliedLevel(CacheHandler.STRAT_DISK);
        }
        return isOk;
    }
    
    public boolean readFromDisk() {
        return readFromDisk(null);
    }

    /**
     * new way of reading from disk.
     */
    public synchronized boolean readFromDisk(Object locker) {
        boolean isOk = false;
        File cacheFile=new File(getCacheNewFileName()); // the actual netbeans.cache file
//        System.out.println("readFromDisk()=" + this.getAbsolutePath());
        if(cacheFile.exists() && cacheFile.canRead() ){
//            System.out.println("reading new=" + getAbsolutePath());
            BufferedReader in = null;
            try{
               in = new BufferedReader(new FileReader(cacheFile));
                String line=null;
                LinkedList processedList = new LinkedList();
                //setFirstTimer(false);
                //boolean reload = false;
                CacheHandler handler = CacheHandler.getInstance();
                while ((line=in.readLine())!=null ){
                    CacheFile file = CvsCacheFile.readFileCache(line, this);
                    /*
                    if (!reload) {
                        reload = isFirstTimer();
                    }
                     */
                    if (file != null) {
                        if (file instanceof CvsCacheFile) {
                            processedList.add(file);
                            handler.addCacheLocker(locker, file);
                        }
                    }
                }
                in.close();
                isOk= true;
                CacheFile[] files = getFiles();
                LinkedList toBeRemoved = new LinkedList();
                for (int i = 0; i < files.length; i++) {
                    CvsCacheFile fil = (CvsCacheFile) files[i];
                    if (!processedList.contains(fil)) {
                        File f = new File(fil.getAbsolutePath());
                        if (!f.exists()) {
//                            System.out.println("in cvscachedir.. removing=" + f.getAbsolutePath());
                            toBeRemoved.add(fil);
                        }
                    }
                }
                if (toBeRemoved.size() > 0) {
                    Iterator it2 = toBeRemoved.iterator();
                    while (it2.hasNext()) {
                        removeFile(((CacheFile)it2.next()).getName(), false);
                    }
                }
                setAppliedLevel(CacheHandler.STRAT_DISK);
                return isOk;
            }catch (IOException e){
//                E.err(e,"readDirFromDiskCache() failed"); // NOI18N
            } finally {
                if (in != null) { 
                    try {in.close();
                    } catch (IOException exc) {}
                    in = null;
                }
            }
        } else {
            // for backward compatibility, do it the old way..
            File oldStorage = new File(getCacheFileName());
            if (oldStorage.exists() && oldStorage.canRead()) {
                readFromDisk_Old();
            } else {
                setAppliedLevel(CacheHandler.STRAT_DISK);
            }
        }
        return isOk;
    }
    
    /**
     * Read just one file from disk cache. This method must not return null.
     * If the file does not exist in the disk cache, create a local file.
     * @param name The file name
     * @return A cache file.
     */
    protected CacheFile readFileFromDisk(String name) {
        CacheFile file = null;
        File cacheFile=new File(getCacheNewFileName()); // the actual netbeans.cache file
//        System.out.println("readFromDisk()=" + this.getAbsolutePath());
        if (cacheFile.exists() && cacheFile.canRead() ){
//            System.out.println("reading new=" + getAbsolutePath());
            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(cacheFile));
                String line=null;
                while ((line=in.readLine()) != null) {
                    CacheFile rfile = CvsCacheFile.readFileCache(line, getCacheName(), dirFile);
                    if (name.equals(rfile.getName())) {
                        file = rfile;
                    }
                }
                in.close();
            } catch (IOException e){
//                E.err(e,"readDirFromDiskCache() failed"); // NOI18N
            } finally {
                if (in != null) { 
                    try {in.close();
                    } catch (IOException exc) {}
                    in = null;
                }
            }
        }
        if (file == null) {
            file = new CvsCacheFile(getCacheName(), name);
        }
        return file;
    }
    
    /**
     * Read just one directory from disk cache. This method must not return null.
     * If the directory does not exist in the disk cache, create a local dir.
     * @param name The directory name
     * @return A cache directory.
     */
    protected CacheDir readDirFromDisk(String name) {
        // directories are not stored in disk cache
        return new CvsCacheDir(getCacheName(), new File(dirFile, name));
    }
    
    public synchronized boolean readVirtualsFromDisk() {
        boolean isOk = false;
        File cacheFile=new File(getCacheVirtualsFileName()); // the actual netbeans.cache file
        if (cacheFile.exists() && cacheFile.canRead() && cacheFile.length() > 0){
//            System.out.println("reading virtuals=" + getAbsolutePath());
            BufferedReader in = null;
            try{
               in = new BufferedReader
                                   (new InputStreamReader
                                     (new FileInputStream(cacheFile)));
                String line=null;
                LinkedList processedList = new LinkedList();
                while ((line=in.readLine())!=null ){
                    CacheFile fil = getFile(line); 
                    if (fil == null) {
                        fil = new CvsCacheFile(JavaCvsCache.JAVA_CACHE_NAME, line);
                        addFile(fil, false);
                    }
                    processedList.add(fil);
                }
                in.close();
                isOk= true;
                CacheFile[] files = getFiles();
                LinkedList toBeRemoved = new LinkedList();
                for (int i = 0; i < files.length; i++) {
                    CvsCacheFile fil = (CvsCacheFile) files[i];
                    if (!processedList.contains(fil)) {
                        File f = new File(fil.getAbsolutePath());
                        if (!f.exists()) {
//                            System.out.println("in cvscachedir.. removing=" + f.getAbsolutePath());
                            toBeRemoved.add(fil);
                        }
                    }
                }
                if (toBeRemoved.size() > 0) {
                    Iterator it2 = toBeRemoved.iterator();
                    while (it2.hasNext()) {
                        removeFile(((CacheFile)it2.next()).getName(), false);
                    }
                }
                return isOk;
            }catch (IOException e){
//                E.err(e,"readDirFromDiskCache() failed"); // NOI18N
            } finally {
                if (in != null) { 
                    try {in.close();
                    } catch (IOException exc) {}
                    in = null;
                }
            }
        } else {
            // for backward compatibility, do it the old way..
            File oldStorage = new File(getCacheFileName());
            if (oldStorage.exists() && oldStorage.canRead()) {
                readFromDisk_Old();
            }
        }
        return isOk;
    }
    
    public void checkServer(Object locker) {
      // thread has to start here..
/*      JavaCvsCache cache = (JavaCvsCache)getCacheObject();
//      cache.prepareCache(new File(this.getAbsolutePath()), false, CacheHandler.STRAT_REFRESHING);
//      cache.fireCacheHandlerEvent(FileSystemCache.EVENT_CHANGED, this);
//      cache.lockFileObjects(this, false);
//      ClientProvider client = cache.getCacheClient();
      JavaCvsFileSystem fs = cache.getInvokingFileSystem();
      if (fs == null) {
//          System.out.println("checkserver error..");
          Thread.dumpStack();
          return;
      }
      fs.clearRunningRefreshSemaphore();
      FileSystemCommandImpl statusComImpl = (FileSystemCommandImpl)fs.createRefresh();
      CvsStatus com = (CvsStatus)statusComImpl.getOuterClassInstance();
      com.setRecursive(false);
      com.setRefreshing(true);
      com.setFiles(new File[] {new File(getAbsolutePath())});
      cache.addRefreshDisplayers((CvsStatus)com);
      com.startCommand();
 
//      setAppliedLevel(CacheHandler.STRAT_ALL);  
      // waits for the commands to finish
 */
    }
    

    
    public void checkServerRecursive(Object locker) {
/*      // thread has to start here..
      JavaCvsCache cache = (JavaCvsCache)getCacheObject();
//      cache.prepareCache(new File(this.getAbsolutePath()), true, CacheHandler.STRAT_REFRESHING);
//      cache.fireCacheHandlerEvent(FileSystemCache.EVENT_CHANGED_RECURSIVELY, this);
//      cache.lockFileObjects(this, true);
//      CvsCacheClient client = cache.getCacheClient();
//      client.doRefreshRecursively(new File(getAbsolutePath()));
      JavaCvsFileSystem fs = cache.getInvokingFileSystem();
      if (fs == null) {
          Thread.dumpStack();
//          System.out.println("checkserver error..");
          return;
      }
      fs.clearRunningRefreshSemaphore();
      FileSystemCommandImpl statusComImpl = (FileSystemCommandImpl)fs.createRefresh();
      CvsStatus com = (CvsStatus)statusComImpl.getOuterClassInstance();
      com.setRecursive(true);
      com.setRefreshing(true);
      com.setFiles(new File[] {new File(getAbsolutePath())});
      cache.addRefreshDisplayers(com);
      com.startCommand(); 
//      setAppliedLevel(CacheHandler.STRAT_ALL);  
      // waits for the commands to finish
 */
    }
    

//--   gets overriden because we need to exclude the CVS directories 
    
    public synchronized String[] getDirContentNames(boolean hideShadow) {
        String[] dirNames = getSubDirNames();
        String[] fileNames = getFileNames();
        int dirSize = dirNames.length + fileNames.length;
        if (dirSize == 0) {
            return null;
        }
        List list = new LinkedList();
        for (int i = 0; i < dirNames.length; i++) {
            if (!dirNames[i].equalsIgnoreCase("CVS")) { // do exclude CVS dir (hidin it from fs children() method) // NOI18N
                list.add(dirNames[i]);
//             System.out.println("subdir=" + subDir.getName());
            }
        }
        boolean hasHidden = false;
        for (int i = 0; i < fileNames.length; i++) {
            if (hideShadow) {
                File file = new File(getFile(fileNames[i]).getAbsolutePath());
                if (file.exists()) {
                    list.add(fileNames[i]);
                } else {
                    hasHidden = true;
                }
            } else {
                list.add(fileNames[i]);
//               System.out.println("adding file=" + cFile.getName());
            }
        }
        if (hasHidden) {
            setStatus(JavaCvsStatusManager.HAS_HIDDEN);
        } else {
            setStatus(" "); // NOI18N
        }
        String[] content = new String[list.size()];
        content = (String[])list.toArray(content);
        return content;
    }
    

    public void rename(File newLocation) {
        super.rename(newLocation);
        setStatus(JavaCvsStatusManager.LOCAL);
    }

    

    
    
    /** Path string to the netbeans.cache file of this directory
     * @deprecated - use the pair getCacheNewFileName() and getCacheVirtualsFileName()
     */
    protected String getCacheFileName() {
        return dirFile.getAbsolutePath() + CACHE_FILENAME;
    }

    /** Path string to the javacvs.cache file of this directory
     */

    protected String getCacheNewFileName() {
        return dirFile.getAbsolutePath() + CACHE_NEW_FILENAME;
    }

    /**
     * returns a filename path to the file that stores the list of virtual files...
     */
    protected String getCacheVirtualsFileName() {
        return dirFile.getAbsolutePath() + CACHE_VIRTUAL_FILENAME;
    }
    
    
    public String getStatus() {
//      if (super.getStatus().equals(" ")) {  
  //      if (isShadow()) return CvsCacheFile.NEEDS_CHECKOUT;   // shadow directory
        File cvsDir = new File(getAbsolutePath() + File.separator + "CVS"); // NOI18N
        if (!cvsDir.exists()) { 
            setStatus(JavaCvsStatusManager.LOCAL);
        }
        return super.getStatus();
/*      } else {
          // when the status was set during the live of the instance
          return super.getStatus();
      }
 */
    }
    public String writeLineToDisk() {
       StringBuffer buff = new StringBuffer("D/"); // NOI18N
        buff.append(getName());
        buff.append("/"); // NOI18N
        buff.append(getStatus());
        buff.append("/"); // NOI18N
        buff.append((getLocker() == null) ? " " : getLocker()); // NOI18N
        buff.append("/"); // NOI18N
        buff.append((getRevision() == null) ? " " : getRevision()); // NOI18N
        buff.append("/");  // NOI18N
        buff.append((getSticky() == null) ? " " : getSticky()); // NOI18N
        buff.append("/");  // NOI18N
        buff.append((getAttr() == null) ? " " : getAttr()); // NOI18N
        buff.append("/");  // NOI18N
        buff.append(getSize()); // NOI18N
        buff.append("/");  // NOI18N
        buff.append((getDate() == null) ? " " : getDate()); // NOI18N
        buff.append("/");  // NOI18N
        buff.append((getTime() == null) ? " " : getTime());        // NOI18N
        return buff.toString();
       
    }
    
    /** adds a file to the directory.
     * @param fireEvent - if true, fires EVENT_ADD event + sets this dir as modified.
     */
    public void addFile(CacheFile fl, boolean fireEvent) {
        synchronized(this) {
            if (getSubDir(fl.getName()) != null) {
                // TODO TO-BE-REMOVED soon.. for debugging purposes only.. should not happen anyway..
                System.out.println("ERROR: attempting to add a file with same name as directory =" + fl.getName());  // NOI18N
                Thread.dumpStack();
                return;
            }
            super.addFile(fl, fireEvent);
        }
    }
    
    /** Removes a directory from the current one.
     * @param fireEvent - if set to true, fires cacheRemoved event;
     * also causes the parent directory to get modified
     *
     */
    public void removeChildDir(String subdirName, boolean fireEvent) {
        synchronized(this) {
            super.removeChildDir(subdirName, fireEvent);
        }
    }
    
    /** Adds a subdirectory to the current one.
     * @param fireEvent - if set to true, fires cacheAdded event + also causes the parent directory to get modified
     */
    public CacheDir addChildDir(CacheDir subDir, boolean fireEvent) {
        synchronized(this) {
            return super.addChildDir(subDir, fireEvent);
        }
    }
    
    /** removes all subdir and file cache objects in this directory.
     */
    public void removeAll(boolean recursively) {
        synchronized(this) {
            super.removeAll(recursively);
        }
    }
    
    /**
     * @param fireEvent - if set to true, fires cacheAdded event;
     * also causes the parent directory to get modified
     *
     */
    public void renameChildDirs(CacheDir newParent, boolean fireEvent) {
        synchronized(this) {
            super.renameChildDirs(newParent, fireEvent);
        }
    }
    
    /** removes a file from the directory.
     * @param fireEvent - if true, fires EVENT_REMOVE event + sets this dir as modified.
     */
    public void removeFile(String flName, boolean fireEvent) {
        synchronized(this) {
            super.removeFile(flName, fireEvent);
        }
    }
    
    /** Sets the dir as modified. Do so when you want the dir to be written to disk cache later.
     *
    public void setModified(boolean mod) {
        super.setModified(mod);
        if (mod) {
            // do immediate write to disk when something changes..
            this.writeToDisk();
            super.setModified(false);
        }
    }
     */
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.