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:net.sourceforge.subsonic.domain.MusicFile.java

/**
 * Returns all music files that are children of this music file.
 *
 * @param includeFiles       Whether files should be included in the result.
 * @param includeDirectories Whether directories should be included in the result.
 * @param sort               Whether to sort files in the same directory.   @return All children music files.
 * @throws IOException If an I/O error occurs.
 *//*from  w ww  .j  av a  2 s  .  c om*/
public List<MusicFile> getChildren(boolean includeFiles, boolean includeDirectories, boolean sort)
        throws IOException {

    FileFilter filter;
    if (includeFiles && includeDirectories) {
        filter = TrueFileFilter.INSTANCE;
    } else if (includeFiles) {
        filter = FileFileFilter.FILE;
    } else if (includeDirectories) {
        filter = DirectoryFileFilter.DIRECTORY;
    } else {
        filter = FalseFileFilter.INSTANCE;
    }

    File[] children = FileUtil.listFiles(file, filter);
    List<MusicFile> result = new ArrayList<MusicFile>(children.length);

    for (File child : children) {
        try {
            if (acceptMedia(child)) {
                result.add(createMusicFile(child));
            }
        } catch (SecurityException x) {
            LOG.warn("Failed to create MusicFile for " + child, x);
        }
    }

    if (sort) {
        Collections.sort(result, new MusicFileSorter());
    }

    return result;
}

From source file:nl.bneijt.javapjson.JavapJsonMojo.java

public void execute() throws MojoExecutionException {
    JsonFactory jsonFactory = new JsonFactory();
    if (!outputDirectory.exists()) {
        throw new MojoExecutionException(
                "No build output directory found. Was looking at \"" + outputDirectory + "\"");
    }/*  w ww  .  j ava2  s. c o m*/

    String jsonDirectory = buildDirectory.getPath() + File.separator + "javap-json";
    File jsonDirectoryFile = new File(jsonDirectory);
    if (!jsonDirectoryFile.exists()) {
        if (!jsonDirectoryFile.mkdir()) {
            throw new MojoExecutionException(
                    "Could not create output directory \"" + jsonDirectoryFile.getPath() + "\"");
        }
        getLog().debug("Created output directory \"" + jsonDirectoryFile.getPath() + "\"");
    }

    for (File classFile : FileUtils.listFiles(outputDirectory, new SuffixFileFilter(CLASS_EXTENSION),
            TrueFileFilter.INSTANCE)) {
        String output = runJavap(classFile);
        JavapLOutput parseL = JavapParser.parseL(output);

        File outputFile = new File(jsonDirectory + File.separator + "current.json");

        try {
            JsonGenerator jsonOutput = jsonFactory.createJsonGenerator(outputFile, JsonEncoding.UTF8);
            parseL.toJsonOnto(jsonOutput);

            //Move file into correct position
            File classDirectory = classFile.getParentFile();
            String classFileName = classFile.getName();
            String restOfDirectory = classDirectory.getPath().substring(outputDirectory.getPath().length());
            File jsonOutputFileDirectory = new File(jsonDirectory + restOfDirectory);
            File jsonOutputFile = new File(jsonOutputFileDirectory.getPath() + File.separator
                    + classFileName.substring(0, classFileName.length() - ".class".length()) + ".json");
            if (!jsonOutputFileDirectory.exists())
                FileUtils.forceMkdir(jsonOutputFileDirectory);
            if (jsonOutputFile.exists()) {
                FileUtils.deleteQuietly(jsonOutputFile);
            }
            FileUtils.moveFile(outputFile, jsonOutputFile);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            throw new MojoExecutionException("Unable to serialize javap output to Json", e);
        }
    }

}

From source file:nl.uva.DataHandler.Indexing.java

@Override
protected void docIndexer() throws Exception {

    try {//from w  w  w .ja v  a2  s. co m
        String CorpusPathString = configFile.getProperty("FILES_PATHS");
        File root = new File(CorpusPathString);
        List<File> files = (List<File>) FileUtils.listFiles(root, TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE);
        for (File file : files) {
            if (file.getName().equals(".DS_Store"))
                continue;
            TextFile tFile = new TextFile(file, root);
            this.IndexDoc(tFile);
        }
    } catch (Exception ex) {
        log.error(ex);
        throw ex;
    }
    System.out.println("number of indexed docs: " + docCount);
}

From source file:no.ntnu.okse.web.controller.LogController.java

/**
 * Private helper method that updates information regarding which log files that are available
 *///w  w w  .j a  v a  2  s.  c  o  m
private static void updateAvailableLogFiles() {
    File dir = new File("logs");
    Collection<File> files = FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);

    files.forEach(f -> {
        if (!fileNames.containsValue(f.getName())) {
            if (f.getName().equalsIgnoreCase("okse.log")) {
                fileNames.put(0, f.getName());
            } else {
                fileNames.put(fileID++, f.getName());
            }
        }
    });

}

From source file:ome.formats.importer.ImportCandidates.java

/**
 * Main constructor which iterates over all the paths calling
 * {@link #walk(File, Collection)} and permitting a descent to the given
 * depth.//ww w . j a v  a 2 s  .c om
 *
 * @param depth
 *            number of directory levels to search down.
 * @param reader
 *            instance used for parsing each of the paths. Not used once the
 *            constructor completes.
 * @param paths
 *            file paths which are searched. May be directories.
 * @param observer
 *            {@link IObserver} which will monitor any exceptions during
 *            {@link OMEROWrapper#setId(String)}. Otherwise no error
 *            reporting takes place.
 */
public ImportCandidates(int depth, OMEROWrapper reader, String[] paths, IObserver observer) {
    super(TrueFileFilter.INSTANCE, depth);
    this.reader = reader;
    this.observer = observer;
    log.info(String.format("Depth: %s Metadata Level: %s", depth, METADATA_LEVEL));

    if (paths != null && paths.length == 2 && "".equals(paths[0]) && "".equals(paths[1])) {
        // Easter egg for testing.
        // groups is not null, therefore usage() won't need to be
        // called.
        System.exit(0);
        return;
    }

    if (paths == null || paths.length == 0) {
        return;
    }

    Groups g;
    try {
        execute(paths);
        total = count;
        count = 0;
        execute(paths);
        g = new Groups(usedBy);
        g.parse(containers);
        long totalElapsed = System.currentTimeMillis() - start;
        log.info(String.format(
                "%s file(s) parsed into " + "%s group(s) with %s call(s) to setId in "
                        + "%sms. (%sms total) [%s unknowns]",
                this.total, size(), this.setids, readerTime, totalElapsed, unknown));
    } catch (CANCEL c) {
        log.info(String.format(
                "Cancelling search after %sms " + "with %s containers found (%sms in %s calls to setIds)",
                (System.currentTimeMillis() - start), containers.size(), readerTime, setids));
        containers.clear();
        cancelled = true;
        g = null;
        total = -1;
        count = -1;
    }

}

From source file:org.ado.musicdroid.view.AppPresenter.java

private List<File> getLocalAlbums() {
    final String musicDirectory = AppConfiguration.getConfigurationProperty("music.dir");
    if (StringUtils.isNotBlank(musicDirectory)) {
        return FileUtils
                .listFilesAndDirs(new File(musicDirectory), DirectoryFileFilter.DIRECTORY,
                        TrueFileFilter.INSTANCE)
                .stream().filter(file -> !file.getAbsolutePath().equals(musicDirectory))
                .sorted((o1, o2) -> o1.getAbsolutePath().compareTo(o2.getAbsolutePath()))
                .collect(Collectors.toList());
    } else {//w w  w . j  a va  2s  . co  m
        return Collections.emptyList();
    }
}

From source file:org.alfresco.repo.content.caching.quota.StandardQuotaStrategyTest.java

@SuppressWarnings("unchecked")
private Collection<File> findCacheFiles() {
    return FileUtils.listFiles(cacheRoot, new SuffixFileFilter(".bin"), TrueFileFilter.INSTANCE);
}

From source file:org.apache.activemq.bugs.AMQ6131Test.java

@Test(timeout = 300000)
public void testDurableWithOnePendingAfterRestartAndIndexRecovery() throws Exception {
    final File persistentDir = getPersistentDir();

    broker.getBroker().addDestination(broker.getAdminConnectionContext(), new ActiveMQTopic("durable.sub"),
            false);/*from  w w  w.j  a  va  2s .c  om*/

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.brokerConnectURI);
    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
    connection.setClientID("myId");
    connection.start();
    final Session jmsSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

    TopicSubscriber durable = jmsSession.createDurableSubscriber(new ActiveMQTopic("durable.sub"), "sub");
    final MessageProducer producer = jmsSession.createProducer(new ActiveMQTopic("durable.sub"));

    final int original = new ArrayList<File>(
            FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE))
                    .size();

    // 100k messages
    final byte[] data = new byte[100000];
    final Random random = new Random();
    random.nextBytes(data);

    // run test with enough messages to create a second journal file
    final AtomicInteger messageCount = new AtomicInteger();
    assertTrue("Should have added a journal file", Wait.waitFor(new Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            final ActiveMQBytesMessage message = new ActiveMQBytesMessage();
            message.setContent(new ByteSequence(data));

            for (int i = 0; i < 100; i++) {
                producer.send(message);
                messageCount.getAndIncrement();
            }

            return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"),
                    TrueFileFilter.INSTANCE)).size() > original;
        }
    }));

    // Consume all but 1 message
    for (int i = 0; i < messageCount.get() - 1; i++) {
        durable.receive();
    }

    durable.close();

    // wait until a journal file has been GC'd after receiving messages
    assertTrue("Subscription should go inactive", Wait.waitFor(new Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return broker.getAdminView().getInactiveDurableTopicSubscribers().length == 1;
        }
    }));

    // force a GC of unneeded journal files
    getBroker().getPersistenceAdapter().checkpoint(true);

    // wait until a journal file has been GC'd after receiving messages
    assertFalse("Should not have garbage collected", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"),
                    TrueFileFilter.INSTANCE)).size() == original;
        }
    }, 5000, 500));

    // stop the broker so we can blow away the index
    getBroker().stop();
    getBroker().waitUntilStopped();

    // delete the index so that the durables are gone from the index
    // The test passes if you take out this delete section
    for (File index : FileUtils.listFiles(persistentDir, new WildcardFileFilter("db.*"),
            TrueFileFilter.INSTANCE)) {
        FileUtils.deleteQuietly(index);
    }

    stopBroker();
    setUpBroker(false);

    assertEquals(1, broker.getAdminView().getInactiveDurableTopicSubscribers().length);
    assertEquals(0, broker.getAdminView().getDurableTopicSubscribers().length);

    ActiveMQConnectionFactory connectionFactory2 = new ActiveMQConnectionFactory(this.brokerConnectURI);
    ActiveMQConnection connection2 = (ActiveMQConnection) connectionFactory2.createConnection();
    connection2.setClientID("myId");
    connection2.start();
    final Session jmsSession2 = connection2.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

    TopicSubscriber durable2 = jmsSession2.createDurableSubscriber(new ActiveMQTopic("durable.sub"), "sub");

    assertEquals(0, broker.getAdminView().getInactiveDurableTopicSubscribers().length);
    assertEquals(1, broker.getAdminView().getDurableTopicSubscribers().length);

    assertNotNull(durable2.receive(5000));
}

From source file:org.apache.activemq.bugs.AMQ6131Test.java

@Test(timeout = 300000)
public void testDurableWithNoMessageAfterRestartAndIndexRecovery() throws Exception {
    final File persistentDir = getPersistentDir();

    broker.getBroker().addDestination(broker.getAdminConnectionContext(), new ActiveMQTopic("durable.sub"),
            false);//  w w  w . ja  va 2s.  co m

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.brokerConnectURI);
    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
    connection.setClientID("myId");
    connection.start();
    final Session jmsSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

    TopicSubscriber durable = jmsSession.createDurableSubscriber(new ActiveMQTopic("durable.sub"), "sub");
    final MessageProducer producer = jmsSession.createProducer(new ActiveMQTopic("durable.sub"));

    final int original = new ArrayList<File>(
            FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE))
                    .size();

    // 100k messages
    final byte[] data = new byte[100000];
    final Random random = new Random();
    random.nextBytes(data);

    // run test with enough messages to create a second journal file
    final AtomicInteger messageCount = new AtomicInteger();
    assertTrue("Should have added a journal file", Wait.waitFor(new Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            final ActiveMQBytesMessage message = new ActiveMQBytesMessage();
            message.setContent(new ByteSequence(data));

            for (int i = 0; i < 100; i++) {
                producer.send(message);
                messageCount.getAndIncrement();
            }

            return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"),
                    TrueFileFilter.INSTANCE)).size() > original;
        }
    }));

    // Consume all messages
    for (int i = 0; i < messageCount.get(); i++) {
        durable.receive();
    }

    durable.close();

    assertTrue("Subscription should go inactive", Wait.waitFor(new Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return broker.getAdminView().getInactiveDurableTopicSubscribers().length == 1;
        }
    }));

    // force a GC of unneeded journal files
    getBroker().getPersistenceAdapter().checkpoint(true);

    // wait until a journal file has been GC'd after receiving messages
    assertTrue("Should have garbage collected", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"),
                    TrueFileFilter.INSTANCE)).size() == original;
        }
    }));

    // stop the broker so we can blow away the index
    getBroker().stop();
    getBroker().waitUntilStopped();

    // delete the index so that the durables are gone from the index
    // The test passes if you take out this delete section
    for (File index : FileUtils.listFiles(persistentDir, new WildcardFileFilter("db.*"),
            TrueFileFilter.INSTANCE)) {
        FileUtils.deleteQuietly(index);
    }

    stopBroker();
    setUpBroker(false);

    assertEquals(1, broker.getAdminView().getInactiveDurableTopicSubscribers().length);
    assertEquals(0, broker.getAdminView().getDurableTopicSubscribers().length);

    ActiveMQConnectionFactory connectionFactory2 = new ActiveMQConnectionFactory(this.brokerConnectURI);
    ActiveMQConnection connection2 = (ActiveMQConnection) connectionFactory2.createConnection();
    connection2.setClientID("myId");
    connection2.start();
    final Session jmsSession2 = connection2.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

    TopicSubscriber durable2 = jmsSession2.createDurableSubscriber(new ActiveMQTopic("durable.sub"), "sub");

    assertEquals(0, broker.getAdminView().getInactiveDurableTopicSubscribers().length);
    assertEquals(1, broker.getAdminView().getDurableTopicSubscribers().length);

    assertNull(durable2.receive(500));
}

From source file:org.apache.activemq.bugs.AMQ6133PersistJMSRedeliveryTest.java

private void restartWithRecovery(File persistenceDir) throws Exception {
    broker.stop();//from w w  w. ja  v  a2  s. c o m
    broker.waitUntilStopped();

    // delete the index so that it needs to be rebuilt from replay
    for (File index : FileUtils.listFiles(persistenceDir, new WildcardFileFilter("db.*"),
            TrueFileFilter.INSTANCE)) {
        FileUtils.deleteQuietly(index);
    }

    createBroker(false);
}