Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

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

Prototype

FilenameFilter

Source Link

Usage

From source file:com.tyro.oss.pact.spring4.pact.consumer.PactPublisher.java

private static File[] findPactFiles(String pactFileRoot) {
    File pactFileRootDirectory = new File(pactFileRoot);
    if (!pactFileRootDirectory.exists() || !pactFileRootDirectory.isDirectory()) {
        throw new IllegalArgumentException(String.format(
                "Pact file root directory either does not exist, or is not a directory: %s", pactFileRoot));
    }/*from   w w w  .j  a  va 2s  . c o m*/

    return pactFileRootDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith("_pacts.json");
        }
    });
}

From source file:org.shareok.data.ouhistory.OuHistoryJournalDataHandlerImpl.java

@Override
public String[] processSafPackages(String dataPath) {
    String[] safPackagePaths = null;
    List<String> safPackagePathList = new ArrayList<>();
    try {// ww  w  .j ava  2  s  . c o m
        OuHistoryJournalDataProcessorImpl processor = (OuHistoryJournalDataProcessorImpl) OuHistoryJournalDataUtil
                .getOuHistoryJournalDataProcessorInstance();
        File dataFolder = new File(dataPath);
        if (!dataFolder.exists() || !dataFolder.isDirectory()) {
            throw new IncorrectDataFolderException(
                    "The uploaded data folder does NOT exist or is NOT a directory!");
        }
        FilenameFilter fileNameFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                if (name.lastIndexOf('.') > 0) {
                    int lastIndex = name.lastIndexOf('.');
                    String str = name.substring(lastIndex);
                    if (str.equals(".csv")) {
                        return true;
                    }
                }
                return false;
            }
        };
        OuHistoryJournalData data = OuHistoryJournalDataUtil.getOuHistoryJournalDataInstance();
        for (File file : dataFolder.listFiles(fileNameFilter)) {
            data.setFilePath(file.getAbsolutePath());
            processor.setJournalData(data);
            String safPath = processor.processSafpackage();
            if (!DocumentProcessorUtil.isEmptyString(safPath)) {
                safPackagePathList.add(safPath);
            }
        }
        safPackagePaths = safPackagePathList.toArray(new String[safPackagePathList.size()]);
    } catch (IncorrectDataFolderException ex) {
        logger.error(ex.getMessage());
    }
    return safPackagePaths;
}

From source file:com.hellblazer.process.impl.AbstractManagedProcess.java

public static UUID getIdFrom(File homeDirectory) {
    if (!homeDirectory.exists() || !homeDirectory.isDirectory()) {
        return null;
    }/* w  w w  .  j  av  a 2s.co m*/
    File[] contents = homeDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(CONTROL_DIR_PREFIX);
        }
    });
    if (contents == null || contents.length == 0) {
        if (log.isLoggable(Level.FINE)) {
            log.fine("Home directory does not exist or does not contain a valid control directory: "
                    + homeDirectory.getAbsolutePath());
        }
        return null;
    }
    if (contents.length > 1) {
        if (log.isLoggable(Level.FINE)) {
            log.fine("Home directory contains more than a single control directory: "
                    + homeDirectory.getAbsolutePath());
        }
        return null;
    }
    String uuidString = contents[0].getName().substring(CONTROL_DIR_PREFIX.length());
    if (uuidString.length() == 0) {
        if (log.isLoggable(Level.FINE)) {
            log.fine("Home directory does not contain a valid control directory: "
                    + homeDirectory.getAbsolutePath());
        }
        return null;
    }
    return UUID.fromString(uuidString);
}

From source file:br.edimarmanica.trinity.intrasitemapping.auto.MappingController.java

private void reading() {
    /**//from   w w  w .jav  a 2  s  . c o  m
     * Lendos os Run02.NR_SHARED_PAGES primeiros elementos de cada offset
     */
    File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset");

    for (int nrOffset = 0; nrOffset < dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".csv");
        }
    }).length; nrOffset++) {
        List<List<String>> offset = new ArrayList<>(); //cada arquivo  um offset

        try (Reader in = new FileReader(dir.getAbsoluteFile() + "/result_" + nrOffset + ".csv")) {
            try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) {
                int nrRegistro = 0;
                for (CSVRecord record : parser) {
                    if (nrRegistro >= Extract.NR_SHARED_PAGES) {
                        break;
                    }

                    for (int nrRegra = 0; nrRegra < record.size(); nrRegra++) {
                        if (nrRegistro == 0) {
                            List<String> regra = new ArrayList<>();
                            try {
                                regra.add(Preprocessing.filter(record.get(nrRegra)));
                            } catch (InvalidValue ex) {
                                regra.add("");
                            }
                            offset.add(regra);
                        } else {
                            try {
                                offset.get(nrRegra).add(Preprocessing.filter(record.get(nrRegra)));
                            } catch (InvalidValue ex) {
                                offset.get(nrRegra).add("");
                            }
                        }
                    }
                    nrRegistro++;
                }
            }
            offsets.add(offset);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MappingController.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MappingController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Mostrando a leitura
     */
    /*for (int i = 1; i < offsets.size(); i++) {
    for (int j = 0; j < 5; j++) {
        System.out.print(offsets.get(i).get(0).get(j) + " - ");
    }
    System.out.println("");
    }*/
}

From source file:de.undercouch.gradle.tasks.download.TempAndMoveTest.java

private File getTempFile() throws IOException {
    File[] files = downloadTaskDir.listFiles(new FilenameFilter() {
        @Override//from  w ww.j ava  2s . c  om
        public boolean accept(File dir, String name) {
            return name.startsWith(dst.getName()) && name.endsWith(".part");
        }
    });

    if (files == null) {
        // downloadTaskDir does not exist
        return null;
    }
    if (files.length > 1) {
        throw new IOException("Multiple temp files in " + downloadTaskDir);
    }

    return files.length == 1 ? files[0] : null;
}

From source file:com.fortify.processrunner.ConfigFilesTest.java

@Test
public void testConfigFiles() {
    String[] files = new File("processrunner-config").list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".xml");
        }/*from   w w w . j  a va  2 s . c o m*/
    });
    for (String file : files) {
        GenericApplicationContext ctx = SpringContextUtil.loadApplicationContextFromFiles(true,
                "processrunner-config/" + file);
        System.out.println(ctx + ": " + Arrays.asList(ctx.getBeanDefinitionNames()));
    }
}

From source file:com.enigmastation.ml.bayes.CorpusTest.java

@Test(groups = { "fulltest" })
public void testCorpus() throws URISyntaxException, IOException, InterruptedException {
    final Classifier classifier = new FisherClassifierImpl();
    ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    // first we expand the test dataset
    URL resource = this.getClass().getResource("/src/test/resources/publiccorpus");
    File resourceFile = new File(resource.toURI());
    String[] dataFileNames = resourceFile.list(new FilenameFilter() {
        @Override//  w  w  w  . ja  v  a2 s.com
        public boolean accept(File dir, String name) {
            return name.endsWith(".bz2");
        }
    });

    List<String> directories = new ArrayList<String>();
    final List<File> trainingFiles = new ArrayList<>();

    for (String fileName : dataFileNames) {
        directories.add(expandFile(fileName));
    }
    // collect every name, plus mark to delete on exit
    for (String inputDirectory : directories) {
        URL url = this.getClass().getResource(inputDirectory);
        File[] dataFiles = new File(url.toURI()).listFiles();
        for (File f : dataFiles) {
            handleFiles(f, trainingFiles);
        }
    }
    long startTime = System.currentTimeMillis();
    final int[] counter = { 0 };
    final int[] marker = { 0 };
    // now let's walk through a training cycle
    for (final File file : trainingFiles) {
        service.submit(new Runnable() {
            @Override
            public void run() {
                if ((++marker[0]) % 100 == 0) {
                    System.out.println("Progress training: " + marker[0] + " of " + trainingFiles.size());
                }
                if (counter[0] > 2) {
                    try {
                        trainWith(classifier, file);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                counter[0] = (counter[0] + 1) % 10;
            }
        });
    }
    service.shutdown();
    service.awaitTermination(2, TimeUnit.HOURS);
    service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    long endTime = System.currentTimeMillis();
    System.out.printf("Training took %d ms%n", (endTime - startTime));
    startTime = System.currentTimeMillis();
    marker[0] = 0;
    // now test against the training data
    for (final File file : trainingFiles) {
        service.submit(new Runnable() {
            public void run() {
                if ((++marker[0]) % 100 == 0) {
                    System.out.println("Progress evaluating: " + marker[0] + " of " + trainingFiles.size());
                }
                if (counter[0] < 3) {
                    try {
                        classify(classifier, file);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                counter[0] = (counter[0] + 1) % 10;
            }
        });
    }
    service.shutdown();
    service.awaitTermination(2, TimeUnit.HOURS);
    endTime = System.currentTimeMillis();
    System.out.printf("Training accuracy: %d tests, %f%% accuracy%n", tests, (hits * 100.0) / tests);
    System.out.printf("Training took %d ms%n", (endTime - startTime));
}

From source file:com.twinsoft.convertigo.engine.util.ZipUtils.java

private static int putEntries(ZipOutputStream zos, String sDir, String sRelativeDir,
        final List<File> excludedFiles) throws Exception {
    Engine.logEngine.trace("==========================================================");
    Engine.logEngine.trace("sDir=" + sDir);
    Engine.logEngine.trace("sRelativeDir=" + sRelativeDir);
    Engine.logEngine.trace("excludedFiles=" + excludedFiles);

    File dir = new File(sDir);
    String[] files = dir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            File file = new File(dir, name);
            return (!excludedFiles.contains(file));
        }/*from   w w  w. ja  v a 2 s.  c  om*/
    });

    Engine.logEngine.trace("files=" + files);

    int nbe = 0;
    for (String file : files) {
        String sDirEntry = sDir + "/" + file;
        String sRelativeDirEntry = sRelativeDir != null ? (sRelativeDir + "/" + file) : file;

        File f = new File(sDirEntry);
        if (!f.isDirectory()) {
            Engine.logEngine.trace("+ " + sDirEntry);
            InputStream fi = new FileInputStream(f);

            try {
                ZipEntry entry = new ZipEntry(sRelativeDirEntry);
                entry.setTime(f.lastModified());
                zos.putNextEntry(entry);
                IOUtils.copy(fi, zos);
                nbe++;
            } finally {
                fi.close();
            }
        } else {
            nbe += putEntries(zos, sDirEntry, sRelativeDirEntry, excludedFiles);
        }
    }
    return nbe;
}

From source file:es.emergya.consultas.FlotaConsultas.java

public static List<String> getAllIcons(String dir) {
    List<String> res = new ArrayList<String>();
    try {/*from   w  ww  . ja va2 s  .com*/
        URL u = FlotaConsultas.class.getResource(dir);
        if (u != null) {
            File f = new File(u.getFile());
            if (f.isDirectory()) {
                FilenameFilter filter = new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.endsWith("_preview.png");
                    }
                };
                for (String path : f.list(filter))
                    res.add(path.substring(0, path.indexOf("_flota_preview")));
            }
        }
    } catch (Throwable t1) {
        log.error(t1, t1);
    }

    return res;
}

From source file:com.shaobo.MyMojo.java

private static List<String> populate(String[] includes) {
    List<String> res = new ArrayList<String>();
    for (String f : includes) {
        if (f.indexOf("**") > 0) {
            int s1 = f.lastIndexOf(47);//slash
            int s2 = f.lastIndexOf(92);//back slash
            String dir = f.substring(0, s1 > s2 ? s1 : s2);
            File directory = new File(dir);
            File[] fs = directory.listFiles(new FilenameFilter() {
                @Override/*from   ww  w. j  ava 2s.c o  m*/
                public boolean accept(File dir, String name) {
                    return name.endsWith("xml");
                }
            });
            for (File path : fs) {
                res.add(path.getAbsolutePath());
            }
        } else {
            res.add(f);
        }
    }
    return res;
}