Example usage for org.apache.commons.io.filefilter FileFilterUtils fileFileFilter

List of usage examples for org.apache.commons.io.filefilter FileFilterUtils fileFileFilter

Introduction

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

Prototype

public static IOFileFilter fileFileFilter() 

Source Link

Document

Returns a filter that checks if the file is a file (and not a directory).

Usage

From source file:eu.optimis.ics.p2p.MyFileAlterationObserver.java

public static void main(String[] args) throws Exception {
    System.out.println("Present Working Directory is : " + System.getProperty("user.dir"));
    File directory = new File(System.getProperty("user.dir") + "/data");

    IOFileFilter files = FileFilterUtils.and(FileFilterUtils.fileFileFilter(),
            FileFilterUtils.suffixFileFilter(".txt"));

    FileAlterationObserver observer = new FileAlterationObserver(directory, files);
    observer.initialize();//from   w w w .  j ava 2  s  .  co  m

    // Add Listener
    MyFileAlterationListener listener = new MyFileAlterationListener();
    observer.addListener(listener);

    FileAlterationMonitor monitor = new FileAlterationMonitor(1000, observer);
    monitor.addObserver(observer);

    monitor.start();

}

From source file:de.fau.osr.util.VisibleFilesTraverser.java

/**
 * Builds a *VisibleFilesTraverser*.//www  . ja v a  2  s.  c om
 * @param startDirectory
 * @param ignoreFileNames
 * @return
 */
public static VisibleFilesTraverser Get(Path startDirectory, String... ignoreFileNames) {
    return new VisibleFilesTraverser(startDirectory, ignoreFileNames, FileFilterUtils.or(
            // Show visible directories
            FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE),
            // Show visible files
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), HiddenFileFilter.VISIBLE)));
}

From source file:ch.ivyteam.ivy.maven.engine.deploy.FileLogForwarder.java

public synchronized void activate() throws MojoExecutionException {
    IOFileFilter logFilter = FileFilterUtils.and(FileFilterUtils.fileFileFilter(),
            FileFilterUtils.nameFileFilter(engineLog.getName()));
    FileAlterationObserver fileObserver = new FileAlterationObserver(engineLog.getParent(), logFilter);
    fileObserver.addListener(new LogModificationListener());
    monitor = new FileAlterationMonitor(100);
    monitor.addObserver(fileObserver);// w w  w. j  ava  2s  . co  m
    try {
        monitor.start();
    } catch (Exception ex) {
        throw new MojoExecutionException("Failed to activate deploy log forwarder", ex);
    }
}

From source file:it.geosolutions.tools.compress.file.test.CompressorTest.java

@Test
public void deflate() throws FileNotFoundException, IOException {
    Collector c = new Collector(FileFilterUtils.fileFileFilter());
    File compressed = Compressor.deflate(destinationFolder, "deflate_test",
            c.collect(folderCompare).toArray(new File[] {}));
    LOGGER.info("Compressed model: " + this.compressed + " length:" + this.compressed.length());
    LOGGER.info("Compressed to compare: " + compressed + " length:" + compressed.length());
    Assert.assertEquals(this.compressed.length(), compressed.length());
}

From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java

private static void addManifestToClasspath(ManifestEntry[] manifestEntries, List<URL> urls) throws Exception {
    for (ManifestEntry manifestEntry : manifestEntries) {
        File manifestEntryFile = new File(manifestEntry.getName());

        if (manifestEntryFile.exists()) {
            if (manifestEntryFile.isDirectory()) {
                ManifestDirectory manifestDir = (ManifestDirectory) manifestEntry;
                IOFileFilter fileFilter = null;

                if (manifestDir.getExcludes().length > 0) {
                    fileFilter = FileFilterUtils.and(FileFilterUtils.fileFileFilter(),
                            FileFilterUtils.notFileFilter(new NameFileFilter(manifestDir.getExcludes())));
                } else {
                    fileFilter = FileFilterUtils.fileFileFilter();
                }//from w w w  . j  a v a  2 s  .c  o  m

                Collection<File> pathFiles = FileUtils.listFiles(manifestEntryFile, fileFilter,
                        FileFilterUtils.trueFileFilter());

                for (File pathFile : pathFiles) {
                    logger.trace("adding library to classpath: " + pathFile.getAbsolutePath());
                    urls.add(pathFile.toURI().toURL());
                }
            } else {
                logger.trace("adding library to classpath: " + manifestEntryFile.getAbsolutePath());
                urls.add(manifestEntryFile.toURI().toURL());
            }
        } else {
            logger.warn("manifest path not found: " + manifestEntryFile.getAbsolutePath());
        }
    }
}

From source file:com.chiorichan.account.adapter.file.FileAdapter.java

public void checkForFiles() {
    File[] files = accountsDirectory.listFiles();

    if (files == null)
        return;//from  w w w  .jav a2s.c om

    for (File f : files)
        if (FileFilterUtils.and(FileFilterUtils.suffixFileFilter("yaml"), FileFilterUtils.fileFileFilter())
                .accept(f))
            if (!preloaded.containsKey(f.getName()))
                preloaded.put(f.getName(), loadFromFile(f));
}

From source file:com.wavemaker.tools.project.upgrade.six_dot_four.RemoveMySQLHBMCatalogUpgradeTask.java

@Override
public void doUpgrade(Project project, UpgradeInfo upgradeInfo) {
    Folder servicesFolder = project.getRootFolder().getFolder("services");
    // Don't bother if we do not have services
    try {/*from   w  w w . j ava  2 s.c o m*/
        if (servicesFolder.exists()) {
            Resource servicesDir = project.getProjectRoot().createRelative("services/");
            ArrayList<String> mySQLServices = new ArrayList<String>();
            try {
                // Find MySQL Services
                IOFileFilter propFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(),
                        FileFilterUtils.suffixFileFilter("properties"));
                List<File> propFiles = new UpgradeFileFinder(propFilter).findFiles(servicesDir.getFile());
                Iterator<File> propIt = propFiles.iterator();
                while (propIt.hasNext()) {
                    File propFile = propIt.next();
                    String propContent = FileUtils.readFileToString(propFile);
                    if (propContent.contains(mySQLStr)) {
                        String propFileName = propFile.getName();
                        int index = propFileName.lastIndexOf(".");
                        if (index > 0 && index <= propFileName.length()) {
                            mySQLServices.add(propFileName.substring(0, index));
                        }
                    }
                }
                // Find HBM files in MySQLServices
                Iterator<String> servIt = mySQLServices.iterator();
                while (servIt.hasNext()) {
                    IOFileFilter hbmFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(),
                            FileFilterUtils.suffixFileFilter("hbm.xml"));
                    String path = servIt.next();
                    Resource mySQLServiceDir = servicesDir
                            .createRelative(path.endsWith("/") ? path : path + "/");
                    List<File> hbmFiles = new UpgradeFileFinder(hbmFilter).findFiles(mySQLServiceDir.getFile());
                    Iterator<File> hbmIt = hbmFiles.iterator();
                    while (hbmIt.hasNext()) {
                        File hbmFile = hbmIt.next();
                        String hbmContent = FileUtils.readFileToString(hbmFile);
                        hbmContent.replaceFirst(catalogStr, replaceStr);
                        FileUtils.writeStringToFile(hbmFile, hbmContent);
                        System.out
                                .println("Project upgrade: Catalog removed from " + hbmFile.getAbsolutePath());
                    }
                }
                if (!mySQLServices.isEmpty()) {
                    upgradeInfo.addMessage("\nMySQL Catalog upgrade task completed. See wm.log for details");
                } else {
                    System.out.println("Project Upgrade: No MySQL Services found");
                }
            } catch (IOException ioe) {
                upgradeInfo
                        .addMessage("\nError removing Catalog from MySQL Services. Check wm.log for details.");
                ioe.printStackTrace();
            }
        } else {
            System.out.println("Project Upgrade: No Services found");
        }
    } catch (IOException e) {
        throw new WMRuntimeException(e);
    }
}

From source file:it.geosolutions.tools.io.CopyTreeTest.java

@Test
public void copyTreeTest() throws Exception {
    LOGGER.info("START: CopyTreeTest");
    File srcMount = TestData.file(this, ".");
    CopyTree act = new CopyTree(
            FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), FileFilterUtils.fileFileFilter()), cs,
            srcMount, destMount);/*from w ww  .j  a va2  s.  c o  m*/
    act.addCollectingListener(new DefaultProgress("COLLECTING"));
    act.addCopyListener(new DefaultProgress("COPY"));
    int workSize = act.copy();
    try {
        while (workSize-- > 0) {
            Future<File> future = cs.take();
            try {
                LOGGER.info("copied file: " + future.get());
            } catch (ExecutionException e) {
                LOGGER.info(e.getLocalizedMessage(), e);
                Assert.fail();
            }
        }
    } catch (InterruptedException e) {
        LOGGER.info(e.getLocalizedMessage(), e);
        Assert.fail();
    }
    LOGGER.info("STOP: CopyTreeTest");
}

From source file:com.ibm.soatf.tool.Utils.java

/**
 * Deletes the directory contents recursively, deletes directories if <code>filesOnly</code> is <code>false</code>
 * @param rootDir the directory which contents you want to remove
 * @param filesOnly if true, keeps directories, deletes only files
 * @throws IOException /*from w  w  w  .  j av  a2 s  .c om*/
 */
public static void deleteDirContent(File rootDir, boolean filesOnly) throws IOException {
    if (!rootDir.isDirectory()) {
        return;
    }
    if (filesOnly) {
        Collection<File> files = FileUtils.listFiles(rootDir, FileFilterUtils.fileFileFilter(),
                FileFilterUtils.directoryFileFilter());
        for (File file : files) {
            if (file.isDirectory()) {
                deleteDirContent(file, filesOnly);
            } else {
                boolean success = file.delete();
                logger.trace("Deleting file " + file.getName() + ": " + (success ? "Success" : "Failure"));
            }
        }
    } else {
        for (File file : rootDir.listFiles()) {
            if (file.isDirectory()) {
                FileUtils.deleteDirectory(file);
            } else {
                boolean success = file.delete();
                logger.trace("Deleting file " + file.getName() + ": " + (success ? "Success" : "Failure"));
            }
        }
    }
}

From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.Read99FilesWithThreeReadersTest.java

@Test
public void readThreeFilesWithThreeReaders() throws InterruptedException, MalformedURLException {
    Map<String, String> answer = getRouteToEndpointPriority();

    //Used for debugging purposes, in-case we need to know which endpoint has what priority
    LOG.info("EndpointSetup: " + answer.toString());

    MockEndpoint first = getMockEndpoint("mock:endFirst");
    first.setExpectedMessageCount(33);/*from  w  ww  .jav a 2  s. c  o m*/
    first.setResultWaitTime(TimeUnit.SECONDS.toMillis(15));
    first.setAssertPeriod(TimeUnit.SECONDS.toMillis(1));

    MockEndpoint second = getMockEndpoint("mock:endSecond");
    second.setExpectedMessageCount(33);
    second.setResultWaitTime(TimeUnit.SECONDS.toMillis(15));
    second.setAssertPeriod(TimeUnit.SECONDS.toMillis(1));

    MockEndpoint third = getMockEndpoint("mock:endThird");
    third.setExpectedMessageCount(33);
    third.setResultWaitTime(TimeUnit.SECONDS.toMillis(15));
    third.setAssertPeriod(TimeUnit.SECONDS.toMillis(1));

    //Wait for the files to be processed
    sleep(30);

    File firstDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel0"));
    File secondDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel1"));
    File thirdDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel2"));

    Assert.assertTrue(".camel0 doesnt exist", firstDirectory.exists());
    Assert.assertTrue(".camel1 doesnt exist", secondDirectory.exists());
    Assert.assertTrue(".camel2 doesnt exist", thirdDirectory.exists());

    Collection<File> firstFiles = FileUtils.listFiles(firstDirectory, FileFilterUtils.fileFileFilter(), null);
    Collection<File> secondFiles = FileUtils.listFiles(secondDirectory, FileFilterUtils.fileFileFilter(), null);
    Collection<File> thirdFiles = FileUtils.listFiles(thirdDirectory, FileFilterUtils.fileFileFilter(), null);

    Assert.assertNotNull(firstFiles);
    Assert.assertNotNull(secondFiles);
    Assert.assertNotNull(thirdFiles);

    //Check the files are unique, and we haven't copied the same file twice
    int firstSize = firstFiles.size();
    int secondSize = secondFiles.size();
    int thirdSize = thirdFiles.size();

    firstFiles.removeAll(secondFiles);
    firstFiles.removeAll(thirdFiles);

    secondFiles.removeAll(firstFiles);
    secondFiles.removeAll(thirdFiles);

    thirdFiles.removeAll(firstFiles);
    thirdFiles.removeAll(secondFiles);

    //If these numbers don't match, we duplicated a file
    Assert.assertEquals("duplicate copy in .camel0", new Integer(firstSize), new Integer(firstFiles.size()));
    Assert.assertEquals("duplicate copy in .camel1", new Integer(secondSize), new Integer(secondFiles.size()));
    Assert.assertEquals("duplicate copy in .camel2", new Integer(thirdSize), new Integer(thirdFiles.size()));

    //Check the expected copied amount is correct
    Assert.assertEquals(new Integer(33), new Integer(firstFiles.size()));
    Assert.assertEquals(new Integer(33), new Integer(secondFiles.size()));
    Assert.assertEquals(new Integer(33), new Integer(thirdFiles.size()));
    Assert.assertEquals(new Integer(99),
            new Integer(firstFiles.size() + secondFiles.size() + thirdFiles.size()));

    //Assert the endpoints last, as there seems to be a strange bug where they fail but the files have been processed,
    //so that would suggest the MockEndpoints are reporting a false-positive
    first.assertIsSatisfied();
    second.assertIsSatisfied();
    third.assertIsSatisfied();
}