Changeset 0eb04fac for router


Ignore:
Timestamp:
Mar 5, 2018 1:16:04 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
665f58d
Parents:
2892382
Message:

Util: Consolidate FileFilters?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java

    r2892382 r0eb04fac  
    1212import java.io.BufferedOutputStream;
    1313import java.io.File;
     14import java.io.FileFilter;
    1415import java.io.FileInputStream;
    15 import java.io.FilenameFilter;
    1616import java.io.Flushable;
    1717import java.io.IOException;
     
    3535import net.i2p.router.Router;
    3636import net.i2p.router.RouterContext;
     37import net.i2p.util.FileSuffixFilter;
    3738import net.i2p.util.FileUtil;
    3839import net.i2p.util.I2PThread;
     
    6162    static final String DIR_PREFIX = "r";
    6263    private static final String B64 = Base64.ALPHABET_I2P;
    63    
     64
    6465    /**
    6566     *  @param dbDir relative path
     
    393394            int routerCount = 0;
    394395
    395             File routerInfoFiles[] = _dbDir.listFiles(RouterInfoFilter.getInstance());
     396            File routerInfoFiles[] = _dbDir.listFiles(RI_FILTER);
    396397            if (_flat) {
    397398                if (routerInfoFiles != null) {
     
    422423                for (int j = 0; j < B64.length(); j++) {
    423424                    File subdir = new File(_dbDir, DIR_PREFIX + B64.charAt(j));
    424                     File[] files = subdir.listFiles(RouterInfoFilter.getInstance());
     425                    File[] files = subdir.listFiles(RI_FILTER);
    425426                    if (files == null)
    426427                        continue;
     
    584585                    subdir.mkdir();
    585586            }
    586             File routerInfoFiles[] = f.listFiles(RouterInfoFilter.getInstance());
     587            File routerInfoFiles[] = f.listFiles(RI_FILTER);
    587588            if (routerInfoFiles != null)
    588589                migrate(f, routerInfoFiles);
     
    598599        for (int j = 0; j < B64.length(); j++) {
    599600            File subdir = new File(dbdir, DIR_PREFIX + B64.charAt(j));
    600             File[] files = subdir.listFiles(RouterInfoFilter.getInstance());
     601            File[] files = subdir.listFiles(RI_FILTER);
    601602            if (files == null)
    602603                continue;
     
    628629    private final static String ROUTERINFO_PREFIX = "routerInfo-";
    629630    private final static String ROUTERINFO_SUFFIX = ".dat";
     631
     632    /** @since 0.9.34 */
     633    public static final FileFilter RI_FILTER = new FileSuffixFilter(ROUTERINFO_PREFIX, ROUTERINFO_SUFFIX);
    630634   
    631635    private static String getLeaseSetName(Hash hash) {
     
    694698        }
    695699    }
    696    
    697     static class RouterInfoFilter implements FilenameFilter {
    698         private static final FilenameFilter _instance = new RouterInfoFilter();
    699         public static final FilenameFilter getInstance() { return _instance; }
    700         public boolean accept(File dir, String name) {
    701             if (name == null) return false;
    702             name = name.toUpperCase(Locale.US);
    703             return (name.startsWith(ROUTERINFO_PREFIX.toUpperCase(Locale.US)) && name.endsWith(ROUTERINFO_SUFFIX.toUpperCase(Locale.US)));
    704         }
    705     }
    706700}
Note: See TracChangeset for help on using the changeset viewer.