Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:com.textocat.textokit.eval.cas.FileListCasDirectory.java

@Override
protected IOFileFilter getSourceFileFilter() {
    final Set<String> included = Sets.newHashSet();
    List<String> includedSrcList;
    try {/*  w ww  . j ava  2  s  .  c  o m*/
        includedSrcList = FileUtils.readLines(listFile, "utf-8");
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    for (String p : includedSrcList) {
        if (StringUtils.isBlank(p)) {
            continue;
        }
        File pFile = new File(p);
        if (pFile.isAbsolute()) {
            included.add(pFile.getAbsolutePath());
        } else {
            included.add(new File(dir, p).getAbsolutePath());
        }
    }
    return FileFilterUtils.asFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return included.contains(f.getAbsolutePath());
        }
    });
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.erroranalysis.CorpusToLatexPrinter.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    File[] files = goldDataDir.listFiles(new FileFilter() {
        @Override/*from  w w w.j a  v a  2s .  c om*/
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".xmi");
        }
    });

    if (files == null || files.length == 0) {
        throw new ResourceInitializationException(
                new IOException("No xmi files found in " + goldDataDir.getAbsolutePath()));
    }

    for (File f : files) {
        fileMapIdFile.put(f.getName().replace(".xmi", ""), f);
    }

    try {
        pw = new PrintWriter(new FileOutputStream(outputFile));
    } catch (FileNotFoundException e) {
        throw new ResourceInitializationException(e);
    }
}

From source file:org.apache.camel.maven.packaging.PackageArchetypeCatalogMojo.java

public static void generateArchetypeCatalog(Log log, MavenProject project, MavenProjectHelper projectHelper,
        File projectBuildDir, File outDir) throws MojoExecutionException, IOException {

    File rootDir = projectBuildDir.getParentFile();
    log.info("Scanning for Camel Maven Archetypes from root directory " + rootDir);

    // find all archetypes which are in the parent dir of the build dir
    File[] dirs = rootDir.listFiles(new FileFilter() {
        @Override/* ww w .  j  av a2s  . com*/
        public boolean accept(File pathname) {
            return pathname.getName().startsWith("camel-archetype") && pathname.isDirectory();
        }
    });

    List<ArchetypeModel> models = new ArrayList<ArchetypeModel>();

    for (File dir : dirs) {
        File pom = new File(dir, "pom.xml");
        if (!pom.exists() && !pom.isFile()) {
            continue;
        }

        boolean parent = false;
        ArchetypeModel model = new ArchetypeModel();

        // just use a simple line by line text parser (no need for DOM) just to grab 4 lines of data
        for (Object o : FileUtils.readLines(pom)) {

            String line = o.toString();

            // we only want to read version from parent
            if (line.contains("<parent>")) {
                parent = true;
                continue;
            }
            if (line.contains("</parent>")) {
                parent = false;
                continue;
            }
            if (parent) {
                // grab version from parent
                String version = between(line, "<version>", "</version>");
                if (version != null) {
                    model.setVersion(version);
                }
                continue;
            }

            String groupId = between(line, "<groupId>", "</groupId>");
            String artifactId = between(line, "<artifactId>", "</artifactId>");
            String description = between(line, "<description>", "</description>");

            if (groupId != null && model.getGroupId() == null) {
                model.setGroupId(groupId);
            }
            if (artifactId != null && model.getArtifactId() == null) {
                model.setArtifactId(artifactId);
            }
            if (description != null && model.getDescription() == null) {
                model.setDescription(description);
            }
        }

        if (model.getGroupId() != null && model.getArtifactId() != null && model.getVersion() != null) {
            models.add(model);
        }
    }

    log.info("Found " + models.size() + " archetypes");

    if (!models.isEmpty()) {

        // make sure there is a dir
        outDir.mkdirs();

        File out = new File(outDir, "archetype-catalog.xml");
        FileOutputStream fos = new FileOutputStream(out, false);

        // write top
        String top = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<archetype-catalog>\n  <archetypes>";
        fos.write(top.getBytes());

        // write each archetype
        for (ArchetypeModel model : models) {
            fos.write("\n    <archetype>".getBytes());
            fos.write(("\n      <groupId>" + model.getGroupId() + "</groupId>").getBytes());
            fos.write(("\n      <artifactId>" + model.getArtifactId() + "</artifactId>").getBytes());
            fos.write(("\n      <version>" + model.getVersion() + "</version>").getBytes());
            if (model.getDescription() != null) {
                fos.write(("\n      <description>" + model.getDescription() + "</description>").getBytes());
            }
            fos.write("\n    </archetype>".getBytes());
        }

        // write bottom
        String bottom = "\n  </archetypes>\n</archetype-catalog>\n";
        fos.write(bottom.getBytes());

        fos.close();

        log.info("Saved archetype catalog to file " + out);

        try {
            if (projectHelper != null) {
                log.info("Attaching archetype catalog to Maven project: " + project.getArtifactId());

                List<String> includes = new ArrayList<String>();
                includes.add("archetype-catalog.xml");
                projectHelper.addResource(project, outDir.getPath(), includes, new ArrayList<String>());
                projectHelper.attachArtifact(project, "xml", "archetype-catalog", out);
            }
        } catch (Exception e) {
            throw new MojoExecutionException("Failed to attach artifact to Maven project. Reason: " + e, e);
        }
    }
}

From source file:it.vige.greenarea.file.ImportaCSVFile.java

@Override
public File recuperaFile() {
    File importFolder = getDirectory();
    FileFilter filter = new FileFilter() {

        @Override/*from   w  w w  . ja  va2  s  .  c o m*/
        public boolean accept(File pathname) {
            long today = 0;
            String todayStr = dateFormat.format(new Date());
            try {
                today = dateFormat.parse(todayStr).getTime();
            } catch (ParseException e) {
                logger.error("greenarea common", e);
            }
            return pathname.lastModified() >= today;
        }
    };
    File[] elencoFile = importFolder.listFiles(filter);
    if (elencoFile != null && elencoFile.length > 0)
        return elencoFile[0];
    else
        return null;
}

From source file:com.screenslicer.core.scrape.trainer.TrainerVisitorExtract.java

@Override
public void init() {
    final ArrayList<String> filenames = new ArrayList<String>();
    final List<String> bump = Arrays.asList(new String[] {});
    new File("./test/data-webpages/").listFiles(new FileFilter() {
        @Override/*w  w  w.  ja  v a  2 s . c  o  m*/
        public boolean accept(File file) {
            if (!file.getAbsolutePath().endsWith("-success") && !file.getAbsolutePath().endsWith("-successnode")
                    && !file.getAbsolutePath().endsWith("-result") && !file.getAbsolutePath().endsWith("-num")
                    && !file.getAbsolutePath().endsWith("-next")) {
                try {
                    if (bump.contains(file.getName())) {
                        resultParents.add(0, FileUtils
                                .readFileToString(new File(file.getAbsolutePath() + "-success", "utf-8")));
                        elements.add(0, DataUtil.load(file, "utf-8", "http://localhost").body());
                        filenames.add(0, file.getName());
                    } else {
                        resultParents.add(FileUtils
                                .readFileToString(new File(file.getAbsolutePath() + "-success", "utf-8")));
                        elements.add(DataUtil.load(file, "utf-8", "http://localhost").body());
                        filenames.add(file.getName());
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return false;
        }
    });
    for (String filename : filenames) {
        System.out.println(filename);
    }
    tmpItems = new Object[resultParents.size()];
}

From source file:com.aliyun.odps.ship.upload.BlockInfoBuilder.java

private void build(File file, ArrayList<BlockInfo> blockIndex)
        throws IOException, TunnelException, ParseException {
    if (file.isDirectory()) {
        File[] fileList = file.listFiles(new FileFilter() {
            @Override//w  w  w. j a  va2 s . c o  m
            public boolean accept(File pathname) {
                return pathname.isFile();
            }
        });
        fileList = Util.sortFiles(fileList);

        for (File f : fileList) {
            build(f, blockIndex);
        }
    } else {
        long fileLength = file.length();
        long i = 0;

        while (i < fileLength) {
            long length = i + blockSize < fileLength ? blockSize : fileLength - i;
            BlockInfo blockInfo = new BlockInfo(Long.valueOf(blockIndex.size() + 1), file, i, length);
            blockIndex.add(blockInfo);
            i += length;
        }
    }
}

From source file:com.mgmtp.jfunk.core.ui.PropertiesComboBoxModel.java

private void initItems() {
    File dir = new File(path);
    if (items.isEmpty()) {
        List<File> files = Arrays.asList(dir.listFiles(new FileFilter() {
            @Override/*from   w  ww. j  a va2  s  .  co  m*/
            public boolean accept(final File file) {
                if (file.getName().matches(propsPrefix + ".*\\." + propsSuffix)) {
                    if (StringUtils.isNotBlank(filter)) {
                        InputStream is = null;
                        try {
                            Properties props = new Properties();
                            is = new FileInputStream(file);
                            props.load(is);
                            if (props.get(filter) == null) {
                                return false;
                            }
                        } catch (IOException ex) {
                            return false;
                        } finally {
                            IOUtils.closeQuietly(is);
                        }
                    }
                    return true;
                }
                return false;
            }
        }));

        for (File file : files) {
            String fileName = file.getName();
            String itemName;
            itemName = includeSuffix ? fileName : fileName.substring(0, fileName.indexOf("." + propsSuffix));
            items.add(itemName);
        }
    }
}

From source file:$.LogParser.java

public File[] getLogFiles(final DateTime date) throws FileNotFoundException {
        File logFolder = new File(logFolderPath);
        if (!logFolder.exists() || !logFolder.canRead()) {
            throw new FileNotFoundException("there is no readable log folder - " + logFolderPath);
        }//ww w.jav a 2s. com

        final String logDateFormatted = FILE_DATE_FORMAT.print(date);
        final long dateMillis = date.getMillis();

        File[] files = logFolder.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                String name = file.getName();
                return name.endsWith(FILE_EXTENSION) // it's a log file
                        && name.contains(logDateFormatted) // it contains the date in the name
                        && file.lastModified() >= dateMillis; // and it's not older than the search date
            }
        });

        Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);

        if (files.length == 0) {
            Log.debug("No log files ending with {}, containing {}, modified after {}, at {}", FILE_EXTENSION,
                    logDateFormatted, date, logFolderPath);
        } else {
            Log.debug("Found log files for {}: {}", date, files);
        }

        return files;
    }

From source file:com.meltmedia.rodimus.DocumentTransformationTest.java

@Test
public void diffWithWhitespace() throws IOException {
    for (File expectedHtmlFile : expectedOutputDir.listFiles(new FileFilter() {
        @Override/*from   w  w w .j  a v  a2  s  . c  o m*/
        public boolean accept(File pathname) {
            return pathname.isFile();
        }
    })) {
        File actualHtmlFile = new File(actualOutputDir, expectedHtmlFile.getName());

        Diff diff = Diff.diff(expectedHtmlFile, actualHtmlFile, false);

        if (!diff.isEmpty()) {
            // build up the output.
            fail(diff.toUnifiedDiff("expected", "actual", new FileReader(expectedHtmlFile),
                    new FileReader(actualHtmlFile), 3));
        }
    }
}

From source file:com.logicalpractice.flumechronicle.channel.ChronicleCleanup.java

private FileFilter directoriesLessThan(final String currentFolder) {
    return new FileFilter() {
        @Override/*  w w  w .  j av  a  2s .c om*/
        public boolean accept(File pathname) {
            String name = pathname.getName();
            return pathname.isDirectory() && name.length() == currentFolder.length() && isAllNumeric(name)
                    && name.compareTo(currentFolder) < 0;
        }
    };
}