
/*
 * Copyright 2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.jcs.yajcache.file;

import java.io.File;
import org.apache.jcs.yajcache.config.YajCacheConfig;
import org.apache.jcs.yajcache.lang.annotation.*;

/**
 * Cache File Utilities.
 *
 * @author Hanson Char
 */
// @CopyRightApache
// http://www.netbeans.org/issues/show_bug.cgi?id=53704
public enum CacheFileUtils {
    inst;
    
    /** 
     * Creates the directory for the specified cache, 
     * including any necessary but nonexistent parent directories.
     * Note that if this operation fails it may have succeeded in 
     * creating some of the necessary parent directories.
     *
     * @return true if succesfull; false otherwise.
     */
    public boolean mkCacheDirs(@NonNullable String cacheName) {
        File dir = this.getCacheDir(cacheName);
        return dir.mkdirs();
    }
    /**
     * Removes the file directory for the specified cache,
     * including all files under the directory.
     */
    boolean rmCacheDir(@NonNullable String cacheName) {
        File dir = this.getCacheDir(cacheName);
        
        if (!dir.exists())
            return true;
        for (File f : dir.listFiles()) {
            f.delete();
        }
        return dir.delete();
    }
    /**
     * Returns the file directory for the specified cache.
     */
    @NonNullable File getCacheDir(@NonNullable String cacheName) {
        return new File(YajCacheConfig.inst.getCacheDir(), cacheName);
    }
    /**
     * Returns the cache file for the specified cache item.
     */
    @NonNullable File getCacheFile(
            @NonNullable String cacheName,
            @NonNullable String key) 
    {
        File dir = this.getCacheDir(cacheName);
        return new File(dir, key);
    }
}

@@ -669,16 +669,119 @@
 o.File;%0A
+import java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A
 import o
@@ -826,16 +826,16 @@
 Config;%0A
-
 import o
@@ -1653,16 +1653,23 @@
  */%0A    
+public 
 boolean 
@@ -1892,24 +1892,24 @@
 ;%0A        %7D%0A
-
         retu
@@ -1923,32 +1923,775 @@
 delete();%0A    %7D%0A
+    public boolean isCacheDirEmpty(@NonNullable String cacheName) %7B%0A        File dir = this.getCacheDir(cacheName);%0A        %0A        if (!dir.exists())%0A            return true;%0A        String%5B%5D list = dir.list();%0A        return list == null %7C%7C list.length == 0;%0A    %7D%0A    public int getCacheDirSize(@NonNullable String cacheName) %7B%0A        File dir = this.getCacheDir(cacheName);%0A        %0A        if (!dir.exists())%0A            return 0;%0A        String%5B%5D list = dir.list();%0A        return list == null ? 0 : list.length;%0A    %7D%0A    public String%5B%5D getCacheDirList(@NonNullable String cacheName) %0A    %7B%0A        File dir = this.getCacheDir(cacheName);%0A        %0A        if (!dir.exists())%0A            return null;%0A        return dir.list();%0A    %7D%0A
     /**%0A     * R

add methods to support file cache