Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

In this page you can find the example usage for java.io FileFilter FileFilter.

Prototype

FileFilter

Source Link

Usage

From source file:nl.b3p.catalog.filetree.FileListHelper.java

private static DirContent getNormalDirContent(File directory, String currentPath) throws IOException {
    DirContent dc = new DirContent();

    File[] dirs = directory.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }/* w w  w.j  a  v  a  2s .  c  om*/
    });

    File[] files = directory.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return !file.isDirectory();
        }
    });

    if (dirs != null) {
        for (File dir : dirs) {
            Dir newDir = new Dir();
            newDir.setName(dir.getName());
            newDir.setPath(currentPath + dir.getName());
            // can be used to attach a different dir icon to it.
            newDir.setIsFGDB(FGDBHelperProxy.isFGDBDirOrInsideFGDBDir(dir));
            dc.getDirs().add(newDir);
        }
    }

    if (files != null) {
        for (File file : files) {
            DirEntry newFile = new DirEntry();
            newFile.setName(file.getName());
            newFile.setPath(currentPath + file.getName());

            boolean isGeo = true;
            Set<String> geoFileExtensions = CatalogAppConfig.getConfig().getGeoFileExtensions();
            if (!geoFileExtensions.isEmpty() && !geoFileExtensions.contains(newFile.getExtension())) {
                isGeo = false;
            }

            newFile.setIsGeo(isGeo);
            dc.getFiles().add(newFile);
        }
    }

    // add stub for directory metadata
    DirEntry newFile = new DirEntry();
    newFile.setName(".metadata");
    newFile.setPath(currentPath + "metadata");
    newFile.setIsGeo(true);
    dc.getFiles().add(newFile);

    filterOutFilesToHide(dc);

    return dc;
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsBlacklisted.java

/**
 * Runs through .sparql files in the BLACKLIST_SPARQL_DIR.
 * /*from  w ww  .  j av  a 2s .  c  om*/
 * The first that returns one or more rows will be cause the user to be
 * blacklisted.
 * 
 * The first variable from the first solution set will be returned.
 */
private static String checkForBlacklisted(Individual ind, ServletContext context) {
    String realPath = context.getRealPath(BLACKLIST_SPARQL_DIR);
    File blacklistDir = new File(realPath);
    if (!blacklistDir.isDirectory() || !blacklistDir.canRead()) {
        log.debug("cannot read blacklist directory " + realPath);
        return NOT_BLACKLISTED;
    }

    log.debug("checking directlry " + realPath + " for blacklisting sparql query files");
    File[] files = blacklistDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".sparql");
        }
    });

    String reasonForBlacklist = NOT_BLACKLISTED;
    for (File file : files) {
        try {
            reasonForBlacklist = runSparqlFileForBlacklist(file, ind, context);
            if (reasonForBlacklist != NOT_BLACKLISTED)
                break;
        } catch (RuntimeException ex) {
            log.error("Could not run blacklist check query for file " + file.getAbsolutePath()
                    + File.separatorChar + file.getName(), ex);
        }
    }
    return reasonForBlacklist;
}

From source file:org.cleverbus.admin.services.log.LogParser.java

public File[] getLogFiles(final DateTime date) throws FileNotFoundException {
    File logFolder = new File(logFolderPath);
    if (!logFolder.exists() || !logFolder.canRead()) {
        throw new FileNotFoundException("there is no readable log folder - " + logFolderPath);
    }/*from   w ww  .j  av  a2  s .  co  m*/

    final String logDateFormatted = FILE_DATE_FORMAT.print(date);
    final long dateMillis = date.getMillis();

    File[] files = logFolder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            String name = file.getName();
            return name.endsWith(FILE_EXTENSION) // it's a log file
                    && name.contains(logDateFormatted) // it contains the date in the name
                    && file.lastModified() >= dateMillis; // and it's not older than the search date
        }
    });

    Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);

    if (files.length == 0) {
        Log.debug("No log files ending with {}, containing {}, modified after {}, at {}", FILE_EXTENSION,
                logDateFormatted, date, logFolderPath);
    } else {
        Log.debug("Found log files for {}: {}", date, files);
    }

    return files;
}

From source file:de.aw.awlib.activities.AWGalleryActivity.java

@SuppressLint("MissingSuperCall")
@Override/* ww  w  . ja  v  a  2s.c o  m*/
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(layout);
    ViewPager pager = (ViewPager) findViewById(R.id.GalleryPager);
    Bundle args = getIntent().getExtras();
    if (args != null) {
        String mDirectory = args.getString(FILENAME);
        if (mDirectory == null) {
            AWApplication.Log("Kein Verzeichnis in Intent unter 'FILENAME'");
            finish();
        } else {
            File directory = new File(mDirectory);
            if (directory.isDirectory()) {
                File[] pictures = directory.listFiles(new FileFilter() {
                    @Override
                    public boolean accept(File pathname) {
                        return pathname.getName().endsWith("jpg");
                    }
                });
                if (pictures != null) {
                    pager.setAdapter(new ScreenSlidePagerAdapter(getSupportFragmentManager(), pictures));
                } else {
                    AWApplication.Log("Kein Zugriff");
                }
            } else {
                AWApplication.Log(mDirectory + " ist kein Verzeichnis");
                finish();
            }
        }
    } else {
        AWApplication.Log("Kein Verzeichnis in Intent unter 'FILENAME'");
        finish();
    }
}

From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java

public void extractApk() throws IOException, URISyntaxException {
    Logger.info("Starting extraction with PSXPeria Extractor version %s", PSXperiaTool.VERSION);
    verifyFiles();//from w  ww  . jav a2 s . c om
    processConfig();
    decodeValues();
    FileFilter filterCompiledRes = new FileFilter() {
        public boolean accept(File file) {
            if (file.getParent() == null || file.getParentFile().getParent() == null)
                return true;
            File parent = file.getParentFile();
            return (!parent.getName().equals("res")) && (!parent.getParentFile().getName().equals("res"));
        }
    };
    nextStep("Extracting APK");
    extractZip(mApkFile, mOutputDir, filterCompiledRes);
    extractZpaks();
    cleanUp();
    moveResourceFiles();
    patchStrings();
    patchEmulator();
    nextStep("Done.");
}

From source file:com.screenslicer.core.scrape.trainer.TrainerVisitorAll.java

@Override
public void init() {
    final ArrayList<String> filenames = new ArrayList<String>();
    final List<String> bump = Arrays.asList(new String[] { "facebook" });
    new File("./test/data-webpages/").listFiles(new FileFilter() {
        @Override/*www.  j ava 2 s .c  o  m*/
        public boolean accept(File file) {
            if (!file.getAbsolutePath().endsWith("-result") && !file.getAbsolutePath().endsWith("-success")
                    && !file.getAbsolutePath().endsWith("-successnode")
                    && !file.getAbsolutePath().endsWith("-num") && !file.getAbsolutePath().endsWith("-next")) {
                try {
                    if (bump.contains(file.getName())) {
                        File numFile = new File(file.getAbsolutePath() + "-num");
                        if (numFile.exists()) {
                            nums.add(0, Integer.parseInt(FileUtils.readFileToString(numFile, "utf-8")));
                        } else {
                            nums.add(0, 10);
                        }
                        elements.add(0,
                                Util.markTestElement(DataUtil.load(file, "utf-8", "http://localhost").body()));
                        filenames.add(0, file.getName());
                    } else if (!BUMP_ONLY) {
                        File numFile = new File(file.getAbsolutePath() + "-num");
                        if (numFile.exists()) {
                            nums.add(Integer.parseInt(FileUtils.readFileToString(numFile, "utf-8")));
                        } else {
                            nums.add(10);
                        }
                        elements.add(
                                Util.markTestElement(DataUtil.load(file, "utf-8", "http://localhost").body()));
                        filenames.add(file.getName());
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return false;
        }
    });
    for (String filename : filenames) {
        System.out.println(filename);
    }
    names = filenames.toArray(new String[0]);
}

From source file:com.yifanlu.Kindle.ExtensionsLoader.java

/**
 * This converts all the extensions into objects using information from their config.xml and returns an array.
 *
 * @return A list of extensions that are loaded or an empty list of no extension is loaded successfully.
 *//*from  w ww.  j a  v a 2  s  . c  o  m*/
public ArrayList loadExtensions() {
    KXmlParser parser = new KXmlParser();
    ArrayList extList = new ArrayList();
    File[] extensions = mDirectory.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }
    });
    int i;
    try {
        for (i = 0; i < extensions.length; i++) {
            File ext = extensions[i];
            KindleLauncher.LOG.info("Loading: " + ext.getAbsolutePath());
            File config = new File(ext, "config.xml");
            Extension extObj = new Extension();
            parser.setInput(new InputStreamReader(new FileInputStream(config)));
            parser.nextTag();
            parser.require(XmlPullParser.START_TAG, null, "extension");
            while (parser.nextTag() != XmlPullParser.END_TAG) {
                parser.require(XmlPullParser.START_TAG, null, null);
                String name = parser.getName();
                if (name.equals("information"))
                    parseInformation(parser, extObj);
                else if (name.equals("menus"))
                    parseMenus(parser, extObj, ext);
                else //skip
                    while (parser.next() != XmlPullParser.END_TAG || !parser.getName().equals(name))
                        ; // this one line does magic to skip all unrelated events
                parser.require(XmlPullParser.END_TAG, null, name);
            }
            parser.require(XmlPullParser.END_TAG, null, "extension");
            parser.next();
            parser.require(XmlPullParser.END_DOCUMENT, null, null);
            extList.add(extObj);
            KindleLauncher.LOG.info(LOADED_EXTENSION,
                    new String[] { extObj.getName(), extObj.getVersion(), extObj.getAuthor(), extObj.getId() },
                    "");
        }
    } catch (IOException e) {
        KindleLauncher.LOG.error("Error reading extension config. " + e.getMessage());
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        KindleLauncher.LOG.error("Error parsing extension config. " + e.getMessage());
        e.printStackTrace();
    } catch (NullPointerException e) {
        KindleLauncher.LOG
                .error("Error parsing extension menu. Required attribute not found. " + e.getMessage());
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        KindleLauncher.LOG
                .error("Error parsing extension menu. Cannot find menu Java class. " + e.getMessage());
        e.printStackTrace();
    } catch (ClassCastException e) {
        KindleLauncher.LOG.error("Error parsing extension menu. " + e.getMessage());
        e.printStackTrace();
    } catch (InstantiationException e) {
        KindleLauncher.LOG
                .error("Error parsing extension menu. Cannot create object from Java class. " + e.getMessage());
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        KindleLauncher.LOG
                .error("Error parsing extension menu. Cannot create object from Java class. " + e.getMessage());
        e.printStackTrace();
    } catch (ParseException e) {
        KindleLauncher.LOG.error("Error parsing extension menu. Cannot parse JSON menu. " + e.getMessage());
        e.printStackTrace();
    }
    return extList;
}

From source file:org.craftercms.search.util.SearchIndexUpdater.java

private void addDirDocsToIndex(String currentIndexId, File dir) {
    File[] listing = dir.listFiles(new FileFilter() {

        public boolean accept(File file) {
            return file.isDirectory() || file.getName().endsWith(".xml");
        }//from  w  ww  . ja v  a  2s  . co m

    });

    for (File file : listing) {
        String fileIndexId = currentIndexId + "/" + file.getName();

        if (file.isFile()) {
            addDocToIndex(fileIndexId, file);
        } else {
            addDirDocsToIndex(fileIndexId, file);
        }
    }
}

From source file:net.sqs2.util.FileUtil.java

/**
 * find files which has specified suffix.
 * /* w  w  w  . jav a2  s . c  o  m*/
 * @param absolutePath
 * @param suffix
 * @return list of files which has specified suffix
 */
public static List<File> find(File absolutePath, final String suffix) {
    return find(absolutePath, new FileFilter() {
        public boolean accept(File file) {
            return file.getName().toLowerCase().endsWith(suffix);
        }
    });
}

From source file:edu.mayo.cts2.framework.core.plugin.SupplementalPropetiesLoader.java

@Override
public void afterPropertiesSet() throws Exception {
    File overridesDir = new File(this.configInitializer.getContextConfigDirectory().getPath() + File.separator
            + ConfigConstants.CONFIG_DIRECTORY);

    if (overridesDir.exists()) {
        FileFilter nonDeploymentConfigFiles = new FileFilter() {
            @Override//from  ww w .j  a v a 2s .c  o m
            public boolean accept(File file) {
                return !StringUtils.equals(ConfigConstants.CTS2_DEPLOYMENT_CONFIG_FILE_NAME, file.getName());
            }
        };

        for (File file : overridesDir.listFiles(nonDeploymentConfigFiles)) {
            Properties props = ConfigUtils.loadProperties(file);
            String pid = (String) props.get(Constants.SERVICE_PID);

            if (pid == null) {
                throw new IllegalStateException(
                        "Overriding Properties File must include a " + Constants.SERVICE_PID + " propery.");
            }

            this.overrides.put(pid, props);
        }
    }
}