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:org.talend.license.LicenseRetriver.java

public void updateLicense() {
    File userHome = new File(System.getProperty("user.home"));
    File licenseRoot = new File(userHome, "licenses");
    File history = new File(licenseRoot, ".history");
    if (!licenseRoot.exists()) {
        licenseRoot.mkdirs();/*from  w w w  .  j  ava 2s.com*/
        history.mkdirs();
    }
    final Collection<File> files = new ArrayList<File>();
    for (String version : versions) {
        Collection<File> fs = updateLicense(version, licenseRoot);
        if (null != fs)
            files.addAll(fs);
    }
    File[] his = licenseRoot.listFiles(new FileFilter() {
        public boolean accept(File f) {
            return f.isFile() && !files.contains(f);
        }
    });
    if (null != his && his.length > 0) {
        for (File file : his) {
            file.renameTo(new File(history, file.getName()));
        }
    }
}

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

@Override
public void init() {
    final ArrayList<String> filenames = new ArrayList<String>();
    final List<String> bump = Arrays.asList(new String[] {});
    new File("./test/data-webpages/").listFiles(new FileFilter() {
        @Override//from  ww  w  . j a v  a 2  s .  c o  m
        public boolean accept(File file) {
            if (!file.getAbsolutePath().endsWith("-success") && !file.getAbsolutePath().endsWith("-successnode")
                    && !file.getAbsolutePath().endsWith("-result") && !file.getAbsolutePath().endsWith("-num")
                    && !file.getAbsolutePath().endsWith("-next")) {
                try {
                    if (bump.contains(file.getName())) {
                        resultParents.add(0, FileUtils
                                .readFileToString(new File(file.getAbsolutePath() + "-success"), "utf-8"));
                        elements.add(0, DataUtil.load(file, "utf-8", "http://localhost").body());
                        filenames.add(0, file.getName());
                    } else {
                        resultParents.add(FileUtils
                                .readFileToString(new File(file.getAbsolutePath() + "-success", "utf-8")));
                        elements.add(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:interactivespaces.resource.analysis.OsgiResourceAnalyzer.java

@Override
public NamedVersionedResourceCollection<NamedVersionedResourceWithData<String>> getResourceCollection(
        File baseDir) {// w  w  w.j av a  2  s. co m
    NamedVersionedResourceCollection<NamedVersionedResourceWithData<String>> resources = NamedVersionedResourceCollection
            .newNamedVersionedResourceCollection();

    File[] files = baseDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".jar");
        }
    });

    if (files != null) {
        for (File file : files) {
            JarFile jarFile = null;
            try {
                jarFile = new JarFile(file);
                Manifest manifest = jarFile.getManifest();
                Attributes attributes = manifest.getMainAttributes();
                String name = attributes.getValue(OSGI_HEADER_SYMBOLIC_NAME);
                String version = attributes.getValue(OSGI_HEADER_VERSION);
                if (name != null && version != null) {
                    NamedVersionedResourceWithData<String> resource = new NamedVersionedResourceWithData<String>(
                            name, Version.parseVersion(version), file.getAbsolutePath());

                    resources.addResource(resource.getName(), resource.getVersion(), resource);
                } else {
                    log.warn(String.format(
                            "Resource %s is not a proper OSGi bundle (missing symbolic name and/or version) and is being ignored.",
                            file.getAbsolutePath()));
                }
            } catch (IOException e) {
                log.error(String.format("Could not open resource file jar manifest for %s",
                        file.getAbsolutePath()), e);
            } finally {
                // For some reason Closeables does not work with JarFile despite it
                // claiming it is Closeable in the Javadoc.
                if (jarFile != null) {
                    try {
                        jarFile.close();
                    } catch (IOException e) {
                        // Don't care.
                    }
                }
            }
        }
    }

    return resources;
}

From source file:com.gargoylesoftware.htmlunit.WebDriverOldTestsTest.java

/**
 * Provides the data, i.e. the files on which the tests should run.
 * TODO: use a dedicated test runner instead of this parameterized runner.
 * @return the tests files on which to run the tests
 *///from   w  w  w .  j  ava2s  .  c o  m
@org.junit.runners.Parameterized.Parameters
public static Collection<File[]> data() {
    final File testsDir = new File("target/generated_tests");
    final List<File[]> response = new ArrayList<File[]>();

    if (testsDir.exists()) {
        final File[] testFiles = testsDir.listFiles(new FileFilter() {
            public boolean accept(final File pathname) {
                final String name = pathname.getName();
                return (name.endsWith(".html.expected") || name.endsWith(".html.FF3.expected"));
            }
        });

        for (final File f : testFiles) {
            response.add(new File[] { f });
        }
    }
    LOG.info(response.size() + " tests found in folder " + testsDir);
    return response;
}

From source file:com.gargoylesoftware.htmlunit.source.BrowserVersionFeaturesSource.java

/**
 * Rename the name specified {@link BrowserVersionFeatures} to the new one, this is applicable only
 * to source folders, not to the test ones.
 *
 * @param features the feature to rename
 * @param newName the new name//w ww .java 2s  . co  m
 * @throws IOException if an error occurs
 */
public void rename(final BrowserVersionFeatures features, final String newName) throws IOException {
    rename(new File(root_, "src/main/java"), features, newName);
    final File propertiesFolder = new File(root_,
            "src/main/resources/com/gargoylesoftware/htmlunit/javascript/configuration");
    for (final File f : propertiesFolder.listFiles(new FileFilter() {
        public boolean accept(final File pathname) {
            return pathname.getName().endsWith(".properties");
        }
    })) {
        rename(f, features.name(), newName);
    }
}

From source file:com.owncloud.android.services.observer.SyncedFolderObserverService.java

@Override
public void onCreate() {
    SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(
            MainApp.getAppContext().getContentResolver());
    monitor = new FileAlterationMonitor(MONITOR_SCAN_INTERVAL);

    fileFilter = new FileFilter() {
        @Override//w w w.jav a 2 s.c om
        public boolean accept(File pathname) {
            return !pathname.getName().startsWith(".") && !pathname.getName().endsWith(".tmp")
                    && !pathname.getName().endsWith(".temp") && !pathname.getName().endsWith(".thumbnail");
        }
    };

    for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
        if (syncedFolder.isEnabled()) {
            AdvancedFileAlterationObserver observer = new AdvancedFileAlterationObserver(syncedFolder,
                    fileFilter);

            try {
                observer.init();
                observer.addListener(new AdvancedFileAlterationListener(syncedFolder));
                monitor.addObserver(observer);
            } catch (Exception e) {
                Log_OC.d(TAG, "Failed getting an observer to intialize " + e);
            }

        }
    }

    try {
        monitor.start();
    } catch (Exception e) {
        Log_OC.d(TAG, "Something went very wrong at onStartCommand");
    }

}

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

@Override
public void init() {
    final ArrayList<String> filenames = new ArrayList<String>();
    final List<String> bump = Arrays.asList(new String[] { "buzzfeed" });
    new File("./test/data-webpages/").listFiles(new FileFilter() {
        @Override/* ww w .j  a  v  a2  s .c o  m*/
        public boolean accept(File file) {
            if (!file.getAbsolutePath().endsWith("-success") && !file.getAbsolutePath().endsWith("-successnode")
                    && !file.getAbsolutePath().endsWith("-result") && !file.getAbsolutePath().endsWith("-num")
                    && !file.getAbsolutePath().endsWith("-next")) {
                try {
                    File fileNext = new File(file.getAbsolutePath() + "-next");
                    if (fileNext.exists()) {
                        if (bump.contains(file.getName())) {
                            nextButtons.add(0, FileUtils.readFileToString(fileNext, "utf-8"));
                            elements.add(0, DataUtil.load(file, "utf-8", "http://localhost").body());
                            filenames.add(0, file.getName());
                        } else {
                            nextButtons.add(FileUtils.readFileToString(fileNext, "utf-8"));
                            elements.add(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.mgmtp.jfunk.core.ui.ScriptsTreeModel.java

private File[] listContents(final File dir) {
    File[] files = dir.listFiles(new FileFilter() {
        @Override//from  ww w  .j  a  v a  2  s  .  c  o m
        public boolean accept(final File file) {
            String ext = FilenameUtils.getExtension(file.getName());
            return file.isDirectory() && !".svn".equals(file.getName()) || "script".equals(ext)
                    || "groovy".equals(ext);
        }
    });
    return files;
}

From source file:atg.tools.dynunit.test.util.FileUtil.java

public static void copyDirectory(@NotNull String srcDir, @NotNull String dstDir,
        @NotNull final List<String> excludes) throws IOException {
    logger.entry(srcDir, dstDir, excludes);
    Validate.notEmpty(srcDir);/*from  w  w  w .  j a v  a  2 s. co  m*/
    Validate.notEmpty(dstDir);
    final File source = new File(srcDir);
    if (!source.exists()) {
        throw logger.throwing(new FileNotFoundException(srcDir));
    }
    final File destination = new File(dstDir);
    FileUtils.copyDirectory(source, destination, new FileFilter() {
        @Override
        public boolean accept(final File file) {
            return excludes.contains(file.getName());
        }
    });
    logger.exit();
}

From source file:com.l2jfree.gameserver.script.faenor.FaenorScriptEngine.java

private void loadPackages() {
    File packDirectory = new File(Config.DATAPACK_ROOT, PACKAGE_DIRECTORY);

    FileFilter fileFilter = new FileFilter() {
        @Override/*from ww w .  j a  va2s.co  m*/
        public boolean accept(File file) {
            return file.getName().endsWith(".zip");
        }
    };

    File[] files = packDirectory.listFiles(fileFilter);
    if (files == null)
        return;
    ZipFile zipPack;

    for (File element : files) {
        try {
            zipPack = new ZipFile(element);
        } catch (ZipException e) {
            _log.error(e.getMessage(), e);
            continue;
        } catch (IOException e) {
            _log.error(e.getMessage(), e);
            continue;
        }

        ScriptPackage module = new ScriptPackage(zipPack);

        List<ScriptDocument> scripts = module.getScriptFiles();
        for (ScriptDocument script : scripts) {
            _scripts.add(script);
        }

        try {
            zipPack.close();
        } catch (IOException e) {
        }
    }
}