Example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Prototype

IOFileFilter INSTANCE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:org.apache.flink.runtime.jobmanager.JobManagerSubmittedJobGraphsRecoveryITCase.java

/**
 * Fails the test if the recovery state (file state backend and ZooKeeper) is not clean.
 *///from w  ww.j  av  a 2s .  c  om
private static void verifyCleanRecoveryState(Configuration config) throws Exception {
    // File state backend empty
    Collection<File> stateHandles = FileUtils.listFiles(FileStateBackendBasePath, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);

    if (!stateHandles.isEmpty()) {
        fail("File state backend is not clean: " + stateHandles);
    }

    // ZooKeeper
    String currentJobsPath = config.getString(ConfigConstants.ZOOKEEPER_JOBGRAPHS_PATH,
            ConfigConstants.DEFAULT_ZOOKEEPER_JOBGRAPHS_PATH);

    Stat stat = ZooKeeper.getClient().checkExists().forPath(currentJobsPath);

    if (stat.getCversion() == 0) {
        // Sanity check: verify that some changes have been performed
        fail("ZooKeeper state for '" + currentJobsPath + "' has not been modified during "
                + "this test. What are you testing?");
    }

    if (stat.getNumChildren() != 0) {
        // Is everything clean again?
        fail("ZooKeeper path '" + currentJobsPath + "' is not clean: "
                + ZooKeeper.getClient().getChildren().forPath(currentJobsPath));
    }
}

From source file:org.apache.flink.test.recovery.JobManagerHAJobGraphRecoveryITCase.java

/**
 * Fails the test if the recovery state (file state backend and ZooKeeper) is not clean.
 *//*  www  . ja  va  2  s. c  o  m*/
private static void verifyCleanRecoveryState(Configuration config) throws Exception {
    // File state backend empty
    Collection<File> stateHandles = FileUtils.listFiles(FileStateBackendBasePath, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);

    if (!stateHandles.isEmpty()) {
        fail("File state backend is not clean: " + stateHandles);
    }

    // ZooKeeper
    String currentJobsPath = config.getString(ConfigConstants.HA_ZOOKEEPER_JOBGRAPHS_PATH,
            ConfigConstants.DEFAULT_ZOOKEEPER_JOBGRAPHS_PATH);

    Stat stat = ZooKeeper.getClient().checkExists().forPath(currentJobsPath);

    if (stat.getCversion() == 0) {
        // Sanity check: verify that some changes have been performed
        fail("ZooKeeper state for '" + currentJobsPath + "' has not been modified during "
                + "this test. What are you testing?");
    }

    if (stat.getNumChildren() != 0) {
        // Is everything clean again?
        fail("ZooKeeper path '" + currentJobsPath + "' is not clean: "
                + ZooKeeper.getClient().getChildren().forPath(currentJobsPath));
    }
}

From source file:org.apache.flink.test.recovery.JobManagerHAJobGraphRecoveryITCase.java

/**
 * Fails the test if the recovery state (file state backend and ZooKeeper) has been cleaned.
 */// w w  w.ja  v a  2 s .  com
private static void verifyRecoveryState(Configuration config) throws Exception {
    // File state backend empty
    Collection<File> stateHandles = FileUtils.listFiles(FileStateBackendBasePath, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);

    if (stateHandles.isEmpty()) {
        fail("File state backend has been cleaned: " + stateHandles);
    }

    // ZooKeeper
    String currentJobsPath = config.getString(ConfigConstants.HA_ZOOKEEPER_JOBGRAPHS_PATH,
            ConfigConstants.DEFAULT_ZOOKEEPER_JOBGRAPHS_PATH);

    Stat stat = ZooKeeper.getClient().checkExists().forPath(currentJobsPath);

    if (stat.getCversion() == 0) {
        // Sanity check: verify that some changes have been performed
        fail("ZooKeeper state for '" + currentJobsPath + "' has not been modified during "
                + "this test. What are you testing?");
    }

    if (stat.getNumChildren() == 0) {
        // Children have been cleaned up?
        fail("ZooKeeper path '" + currentJobsPath + "' has been cleaned: "
                + ZooKeeper.getClient().getChildren().forPath(currentJobsPath));
    }
}

From source file:org.apache.flume.source.syncdir.SyncDirFileLineReader.java

/**
 * Find the next file in the directory by walking through directory tree.
 *
 * @return the next file//  ww  w.j  a  v  a 2 s . com
 */
private Optional<ResettableFileLineReader> getNextFile() {
    if (null != filesIterator && !filesIterator.hasNext()) {
        filesIterator = null;
        return Optional.absent();
    }
    if (null == filesIterator) {
        filesIterator = FileUtils.iterateFiles(directory, new IOFileFilter() {
            @Override
            public boolean accept(File file) {
                if (!file.exists())
                    return false; // skip non-exist files in iterator
                if (file.isFile()) {
                    String fileStr = file.getName();
                    if (!(fileStr.endsWith(endFileSuffix) || fileStr.endsWith(statsFileSuffix)
                            || fileStr.endsWith(finishedStatsFileSuffix))) {
                        File finishedMarkFile = new File(file.getPath() + finishedStatsFileSuffix);
                        if (!finishedMarkFile.exists())
                            return true;
                    }
                }
                return false;
            }

            @Override
            public boolean accept(File dir, String name) {
                return false;
            }
        }, TrueFileFilter.INSTANCE);
    }

    File nextFile;
    boolean fileEnded;
    if (!filesIterator.hasNext())
        return Optional.absent();
    /* checking file's reading progress, skip if needed */
    nextFile = filesIterator.next();
    logger.debug("treating next file: {}", nextFile);
    fileEnded = new File(nextFile.getPath() + endFileSuffix).exists();
    if (fileEnded) {
        logger.debug("file {} marked as ended", nextFile);
    }
    try {
        ResettableFileLineReader file = new ResettableFileLineReader(nextFile, fileEnded, statsFilePrefix,
                statsFileSuffix, finishedStatsFileSuffix);
        return Optional.of(file);
    } catch (IOException e) {
        logger.error("Exception opening file: " + nextFile, e);
        return Optional.absent();
    }
}

From source file:org.apache.fop.fotreetest.FOTreeTestSuite.java

private static void addXMLTestCases(TestSuite suite) throws IOException {
    File mainDir = new File("test/fotree");

    final FOTreeTester tester = new FOTreeTester();

    IOFileFilter filter;/*from   w w  w.j  a  v  a2 s.  c  o  m*/
    String single = System.getProperty("fop.fotree.single");
    String startsWith = System.getProperty("fop.fotree.starts-with");
    if (single != null) {
        filter = new NameFileFilter(single);
    } else if (startsWith != null) {
        filter = new PrefixFileFilter(startsWith);
        filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
    } else {
        filter = new SuffixFileFilter(".fo");
        filter = LayoutEngineTestSuite.decorateWithDisabledList(filter);
    }
    Collection files = FileUtils.listFiles(new File(mainDir, "testcases"), filter, TrueFileFilter.INSTANCE);
    String privateTests = System.getProperty("fop.fotree.private");
    if ("true".equalsIgnoreCase(privateTests)) {
        Collection privateFiles = FileUtils.listFiles(new File(mainDir, "private-testcases"), filter,
                TrueFileFilter.INSTANCE);
        files.addAll(privateFiles);
    }
    Iterator i = files.iterator();
    while (i.hasNext()) {
        File f = (File) i.next();
        addTestCase(suite, tester, f);
    }
}

From source file:org.apache.fop.layoutengine.LayoutEngineTestSuite.java

/**
 * @return a Collection of File instances containing all the test cases set up for processing.
 * @throws IOException if there's a problem gathering the list of test files
 *//*from www  .  j  a v a2 s  . c  o m*/
public static Collection getTestFiles() throws IOException {
    File mainDir = new File("test/layoutengine");
    IOFileFilter filter;
    String single = System.getProperty("fop.layoutengine.single");
    String startsWith = System.getProperty("fop.layoutengine.starts-with");
    if (single != null) {
        filter = new NameFileFilter(single);
    } else if (startsWith != null) {
        filter = new PrefixFileFilter(startsWith);
        filter = new AndFileFilter(filter, new SuffixFileFilter(".xml"));
        filter = decorateWithDisabledList(filter);
    } else {
        filter = new SuffixFileFilter(".xml");
        filter = decorateWithDisabledList(filter);
    }
    String testset = System.getProperty("fop.layoutengine.testset");
    if (testset == null) {
        testset = "standard";
    }
    Collection files = FileUtils.listFiles(new File(mainDir, testset + "-testcases"), filter,
            TrueFileFilter.INSTANCE);
    String privateTests = System.getProperty("fop.layoutengine.private");
    if ("true".equalsIgnoreCase(privateTests)) {
        Collection privateFiles = FileUtils.listFiles(new File(mainDir, "private-testcases"), filter,
                TrueFileFilter.INSTANCE);
        files.addAll(privateFiles);
    }
    return files;
}

From source file:org.apache.fop.layoutengine.LayoutEngineTestUtils.java

/**
 * Returns the test files matching the given configuration.
 *
 * @param testConfig the test configuration
 * @return the applicable test cases// w w  w . j  a  v a2  s .co m
 */
public static Collection<File[]> getTestFiles(TestFilesConfiguration testConfig) {
    File mainDir = testConfig.getTestDirectory();
    IOFileFilter filter;
    String single = testConfig.getSingleTest();
    String startsWith = testConfig.getStartsWith();
    if (single != null) {
        filter = new NameFileFilter(single);
    } else if (startsWith != null) {
        filter = new PrefixFileFilter(startsWith);
        filter = new AndFileFilter(filter, new SuffixFileFilter(testConfig.getFileSuffix()));
        filter = decorateWithDisabledList(filter, testConfig.getDisabledTests());
    } else {
        filter = new SuffixFileFilter(testConfig.getFileSuffix());
        filter = decorateWithDisabledList(filter, testConfig.getDisabledTests());
    }
    String testset = testConfig.getTestSet();

    Collection<File> files = FileUtils.listFiles(new File(mainDir, testset), filter, TrueFileFilter.INSTANCE);
    if (testConfig.hasPrivateTests()) {
        Collection<File> privateFiles = FileUtils.listFiles(new File(mainDir, "private-testcases"), filter,
                TrueFileFilter.INSTANCE);
        files.addAll(privateFiles);
    }

    Collection<File[]> parametersForJUnit4 = new ArrayList<File[]>();
    for (File f : files) {
        parametersForJUnit4.add(new File[] { f });
    }

    return parametersForJUnit4;
}

From source file:org.apache.hadoop.gateway.util.ServiceDefinitionsLoader.java

private static Collection<File> getFileList(File servicesDir) {
    Collection<File> files;
    if (servicesDir.exists() && servicesDir.isDirectory()) {
        files = FileUtils.listFiles(servicesDir, new IOFileFilter() {
            @Override//from w w  w.ja va2  s  . c  o  m
            public boolean accept(File file) {
                return file.getName().contains(SERVICE_FILE_NAME);
            }

            @Override
            public boolean accept(File dir, String name) {
                return name.contains(SERVICE_FILE_NAME);
            }
        }, TrueFileFilter.INSTANCE);
    } else {
        files = new HashSet<>();
    }

    return files;
}

From source file:org.apache.log.extractor.App.java

private List<File> getLogFiles(String[] logLocations) throws IOException {
    final String logFileNamePattern = config.getString("log.oozie.filename.pattern");
    Set<File> uniqueFiles = new HashSet<File>();
    for (String oneLocation : logLocations) {
        File file = new File(oneLocation);
        if (!file.isFile()) {
            final Collection listFiles = FileUtils.listFiles(file,
                    new WildcardFileFilter(logFileNamePattern, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
            uniqueFiles.addAll(listFiles);
        } else {/*from w  ww  . j a va2s . c  o  m*/
            uniqueFiles.add(file);
        }
    }
    return new ArrayList<File>(uniqueFiles);
}

From source file:org.apache.maven.plugin.cxx.GenerateMojo.java

protected Map<String, String> listResourceFolderContent(String path, Map valuesMap) {
    String location = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    final File jarFile = new File(location);

    HashMap<String, String> resources = new HashMap<String, String>();
    StrSubstitutor substitutor = new StrSubstitutor(valuesMap);

    path = (StringUtils.isEmpty(path)) ? "" : path + "/";
    getLog().debug("listResourceFolderContent : " + location + ", sublocation : " + path);
    if (jarFile.isFile()) {
        getLog().debug("listResourceFolderContent : jar case");
        try {//from   w  ww  .j  a va2 s  . c  o  m
            final JarFile jar = new JarFile(jarFile);
            final Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                final String name = entries.nextElement().getName();
                if (name.startsWith(path)) {
                    String resourceFile = File.separator + name;
                    if (!(resourceFile.endsWith("/") || resourceFile.endsWith("\\"))) {
                        getLog().debug("resource entry = " + resourceFile);
                        String destFile = substitutor.replace(resourceFile);
                        getLog().debug("become entry = " + destFile);
                        resources.put(resourceFile, destFile);
                    }
                }
            }
            jar.close();
        } catch (IOException ex) {
            getLog().error("unable to list jar content : " + ex);
        }
    } else {
        getLog().debug("listResourceFolderContent : file case");
        //final URL url = Launcher.class.getResource("/" + path);
        final URL url = getClass().getResource("/" + path);
        if (url != null) {
            try {
                final File names = new File(url.toURI());
                Collection<File> entries = FileUtils.listFiles(names, TrueFileFilter.INSTANCE,
                        TrueFileFilter.INSTANCE);
                for (File name : entries) {
                    String resourceFile = name.getPath();
                    if (!(resourceFile.endsWith("/") || resourceFile.endsWith("\\"))) {
                        getLog().debug("resource entry = " + resourceFile);
                        String destFile = substitutor.replace(resourceFile);
                        destFile = destFile.replaceFirst(Pattern.quote(location), "/");
                        getLog().debug("become entry = " + destFile);
                        resources.put(resourceFile, destFile);
                    }
                }
            } catch (URISyntaxException ex) {
                // never happens
            }
        }
    }
    return resources;
}