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:br.edimarmanica.trinity.intrasitemapping.manual.OffsetToRule.java

public void execute() {
    readMappings();//from   ww  w.j a  va 2 s  .  c o  m

    File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset");

    for (File offset : dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".csv");
        }
    })) {

        try (Reader in = new FileReader(offset)) {
            try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) {
                for (CSVRecord record : parser) {
                    String page = record.get(0);
                    if (pages.contains(page)) {
                        continue;
                    } else {
                        pages.add(page);
                    }

                    List<String> dataRecord = new ArrayList<>();
                    for (Attribute attr : site.getDomain().getAttributes()) {
                        try {
                            int group = mappings.get(offset.getName()).get(attr.getAttributeID());

                            if (group != -1) {
                                dataRecord.add(record.get(group));
                            } else {
                                dataRecord.add("");
                            }
                        } catch (Exception ex) {
                            dataRecord.add("");
                        }
                    }
                    print(page, dataRecord);
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Mapping.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Mapping.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:com.sarbyn.ath.explorer.AppAnalyzer.java

private File getResFolder() {
    File[] searchForResFolder = appFolder.listFiles(new FilenameFilter() {

        @Override//  www.  j  a  va2 s  . c o m
        public boolean accept(File dir, String name) {
            return TRANSLATION_PARENT_FOLDER.equals(name);
        }
    });
    return searchForResFolder[0];
}

From source file:gov.wa.wsdot.cms.utils.Migration.java

/**
 * Delete resource files named after GUIDs.
 *///from  ww  w .ja  v  a2s  .c o m
public static void deleteResources(String archiveFolder) {
    File files[] = (new File(archiveFolder)).listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File archiveFolder, String name) {
            return name.matches("res[A-Z0-9]{32}.*");
        }
    });

    System.out.println("Deleting resources.");

    for (File file : files) {
        if (!file.delete()) {
            System.out.println("Can't remove: " + file.getAbsolutePath());
        } else {
            System.out.println("Removed: " + file.getAbsolutePath());
        }
    }

    System.out.println("Done.");
}

From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java

private static void deleteTasks() {
    File dir = TASK_DIR;// ww  w . j a v a 2s.co m

    File[] toDelete = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            if (name.startsWith(MUTATION_TASK_PROJECT_FILE_PREFIX)) {
                return true;
            }
            return false;
        }

    });
    if (toDelete == null) {
        logger.info("Got no files to delete in directory" + dir);
        return;
    }
    for (File d : toDelete) {
        boolean delete = d.delete();
        if (delete) {
            logger.info("Deleted task: " + d);
        } else {
            logger.info("Could not delete task: " + d);
        }
    }
}

From source file:com.payne.file.FileDelete.java

public boolean delFilterFile(File filePath, final String filter) {
    boolean result = false;

    if (filePath.isDirectory()) {
        File[] files = filePath.listFiles(new FilenameFilter() {
            @Override/*  w w  w.  ja  va2  s . c  o  m*/
            public boolean accept(File dir, String name) {
                if (dir != null && name.contains(filter)) {
                    return true;
                } else {
                    return false;
                }
            }

        });
        for (File file : files) {
            //
            result = deleteFile(file);
            if (!result) {
                System.out.println("??" + file.getName());
                break;
            }
        }
        return result;
    } else if (filePath.isFile()) {
        if (filePath.getName().contains(filter)) {
            result = filePath.delete();
        }
    }
    return result;
}

From source file:com.joliciel.jochre.doc.ImageDocumentExtractorImpl.java

@Override
public JochreDocument extractDocument() {
    LOG.debug("ImageDocumentExtractorImpl.extractDocument");
    try {//from ww  w . j  av  a 2  s.  com
        File[] files = new File[1];

        if (imageFile.isDirectory()) {
            files = imageFile.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return (name.toLowerCase().endsWith(".png") || name.toLowerCase().endsWith(".jpg")
                            || name.toLowerCase().endsWith(".jpeg") || name.toLowerCase().endsWith(".gif"));
                }
            });
        } else {
            files[0] = imageFile;
        }

        JochreDocument doc = this.documentProcessor.onDocumentStart();
        doc.setTotalPageCount(files.length);

        int currentPageNumber = this.pageNumber;
        for (File file : files) {
            JochrePage page = this.documentProcessor.onPageStart(currentPageNumber++);

            BufferedImage image = ImageIO.read(file);
            String imageName = file.getName();

            if (currentMonitor != null && documentProcessor instanceof Monitorable) {
                ProgressMonitor monitor = ((Monitorable) documentProcessor).monitorTask();
                double percentAllotted = (1 / (double) (files.length));
                currentMonitor.startTask(monitor, percentAllotted);
            }

            documentProcessor.onImageFound(page, image, imageName, 0);
            if (currentMonitor != null && documentProcessor instanceof Monitorable) {
                currentMonitor.endTask();
            }

            this.documentProcessor.onPageComplete(page);
        }
        this.documentProcessor.onDocumentComplete(doc);

        if (currentMonitor != null)
            currentMonitor.setFinished(true);
        return doc;
    } catch (Exception e) {
        LOG.debug("Exception occurred. Have monitor? " + currentMonitor);
        if (currentMonitor != null)
            currentMonitor.setException(e);
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    } finally {
        LOG.debug("Exit ImageDocumentExtractorImpl.extractDocument");
    }
}

From source file:com.openshift.blog.example.fis.process.CountryProcessor.java

/**
 * Create a filename filter that limits file responses to csv types.
 * /*w  w w .  j  a v a  2s  .  c om*/
 * @return filenamefilter
 */
private FilenameFilter getFilenameFilter() {
    FilenameFilter csvFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            String lowercaseName = name.toLowerCase();
            if (lowercaseName.endsWith(".csv")) {
                return true;
            } else {
                return false;
            }
        }
    };

    return csvFilter;
}

From source file:com.mgmtp.perfload.core.test.it.VerifierIT.java

/**
 * Get all log files the fit to the given pattern in the given directory
 * /*ww  w.j  a va  2 s  .  c  o  m*/
 * @param clientDir
 *            The directory where to look for the files
 * @param logFilePattern
 *            The pattern the log filename must match
 * @return All log files in the given directory that match to the given pattern.
 */
protected File[] getLogs(final File clientDir, final Pattern logFilePattern) {
    File[] logs = clientDir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            Matcher matcher = logFilePattern.matcher(name);
            return matcher.find();
        }
    });

    return logs;

}

From source file:com.github.ipaas.ifw.front.rewrite.FisRewrite.java

private static void initAll() throws FisException {
    String configDirPath = FisRewrite.class.getClassLoader().getResource(DEFAULT_SERVER_CONFIG_DIR).getFile();

    File serverJsonDir = new File(configDirPath);
    String[] serverJsonFiles = serverJsonDir.list();

    FilenameFilter defaultFileNameFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            boolean isMatch = name.equals(DEFAULT_SERVER_CONFIG_FILE);
            return isMatch;

        }//from   w  w  w  .  ja  v  a2 s.c o  m
    };
    FilenameFilter nameSpaceFileNameFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            boolean isMatch = name.endsWith("-" + DEFAULT_SERVER_CONFIG_FILE);
            return isMatch;

        }
    };

    String[] childrenFileNames = serverJsonDir.list(defaultFileNameFilter);
    String[] nameSpacechildrenFileNames = serverJsonDir.list(nameSpaceFileNameFilter);

    if ((null == childrenFileNames || 0 == childrenFileNames.length)
            && (null == nameSpacechildrenFileNames || 0 == nameSpacechildrenFileNames.length)) {
        throw new FisException("server config File server.json Not Found!");
    }

    // ?
    if (null != childrenFileNames || 0 < childrenFileNames.length) {
        for (int i = 0; i < childrenFileNames.length; i++) {
            FisRewrite.init(childrenFileNames[i]);
        }
    }

    // ???
    if (null != nameSpacechildrenFileNames || 0 < nameSpacechildrenFileNames.length) {
        for (int i = 0; i < nameSpacechildrenFileNames.length; i++) {
            FisRewrite.init(nameSpacechildrenFileNames[i]);
        }
    }

    // for (int i = 0, len = mapJsonFiles.length; i < len; i++) {
    // String fileName = mapJsonFiles[i];
    // if (fileName.equals(FisResource.DEFAULT_RES_MAPPING_FILE)) {
    // FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR,
    // FisResource.DEFAULT_NS_GLOBAL);
    // } else {
    // int pos = fileName.indexOf("-" +
    // FisResource.DEFAULT_RES_MAPPING_FILE);
    // if (pos > 0) {
    // String namespace = fileName.substring(0, pos);
    // FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR,
    // namespace);
    // }
    // }
    // }
}

From source file:hudson.maven.Maven3BuildTest.java

public void testSimpleMaven3BuildRedeployPublisher() throws Exception {

    MavenModuleSet m = createMavenProject();
    MavenInstallation mavenInstallation = configureMaven3();
    m.setMaven(mavenInstallation.getName());
    File repo = createTmpDir();//from  w  w w  .j  av  a 2 s  .com
    FileUtils.cleanDirectory(repo);
    m.getReporters().add(new TestReporter());
    m.getPublishersList().add(new RedeployPublisher("", repo.toURI().toString(), true, false));
    m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
    m.setGoals("clean install");
    MavenModuleSetBuild b = buildAndAssertSuccess(m);
    assertTrue(MavenUtil.maven3orLater(b.getMavenVersionUsed()));
    File artifactDir = new File(repo, "com/mycompany/app/my-app/1.7-SNAPSHOT/");
    String[] files = artifactDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            System.out.println("file name : " + name);
            return name.endsWith(".jar");
        }
    });
    assertTrue("SNAPSHOT exist", !files[0].contains("SNAPSHOT"));
    assertTrue("file not ended with -1.jar", files[0].endsWith("-1.jar"));
}