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.meltmedia.cadmium.core.FileSystemManager.java

public static String[] getFilesInDirectory(String directory, final String ext) {
    File dir = new File(directory);
    if (dir.isDirectory()) {
        String files[] = null;//from  w  ww  .j  a v a  2s .  c o m
        if (ext != null && ext.length() > 0) {
            files = dir.list(new FilenameFilter() {

                @Override
                public boolean accept(File file, String name) {
                    return !file.isDirectory() && name.endsWith("." + ext);
                }

            });
        } else {
            files = dir.list();
        }
        if (files != null) {
            return files;
        }
    }

    return new String[] {};
}

From source file:com.streamsets.datacollector.util.SystemProcessImpl.java

static void clean(File tempDir, int limit) {
    String[] files = tempDir.list(new FilenameFilter() {
        @Override/*from   w w  w  . ja  v a 2s  .  c  o  m*/
        public boolean accept(File dir, String name) {
            return name.endsWith(OUT_EXT) || name.endsWith(ERR_EXT);
        }
    });
    if (files != null && files.length > limit) {
        List<String> fileList = new ArrayList<>(files.length);
        fileList.addAll(Arrays.asList(files));
        Collections.sort(fileList);
        while (fileList.size() > limit) {
            File file = new File(tempDir, fileList.remove(0));
            if (!FileUtils.deleteQuietly(file)) {
                LOG.warn("Could not delete: {}", file);
            }
        }
    }
}

From source file:org.obiba.onyx.core.etl.participant.impl.ArchiveAppointmentFileTasklet.java

private FilenameFilter getFilter() {
    return (new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return participantReader.accept(dir, name);
        }/*from w  ww .j  a va 2 s .com*/
    });
}

From source file:com.nominanuda.springsoy.SoySource.java

private void compile(String lang) throws IOException {
    File[] templateFiles = templatesLocation.getFile().listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".soy");
        }/*from  www . j  a  v  a 2s.  c o m*/
    });
    SoyFileSet.Builder builder = new SoyFileSet.Builder();
    List<String> jsTplNames = new LinkedList<String>();
    for (File templateFile : templateFiles) {
        builder.add(templateFile);
        jsTplNames.add(templateFile.getName());
    }
    SoyFileSet soyFileSet = builder.build();
    List<String> jsTpls = soyFileSet.compileToJsSrc(new SoyJsSrcOptions(), getBundle(lang));
    for (String jsSrc : jsTpls) {
        BufferedReader br = new BufferedReader(new StringReader(jsSrc));
        String line;
        while ((line = br.readLine()) != null) {
            Matcher m = FUNC_DECL.matcher(line);
            if (m.find()) {
                functionNames.add(m.group(1));
            }
        }
    }
    Map<String, String> jsTplMap = new HashMap<String, String>();
    int len = jsTplNames.size();
    for (int i = 0; i < len; i++) {
        jsTplMap.put(jsTplNames.get(i), jsTpls.get(i));
    }
    jsTemplatesCache.put(lang, jsTplMap);
    tofuCache.put(lang, soyFileSet.compileToTofu());
}

From source file:disko.flow.analyzers.XQueryAnalyzer.java

/**
 * Adds all the queries found in the directory defined by system property
 * xqueries.home, or if it's not found, the default location
 * DEFAULT_XQUERIES_HOME// ww  w.  j a  v  a 2s . co m
 */
private void addDefaultXQueries() {
    String xqueriesHomeProperty = System.getProperty("xqueries.home");
    if (xqueriesHomeProperty == null)
        xqueriesHomeProperty = DEFAULT_XQUERIES_HOME;
    File xqueriesHome = new File(xqueriesHomeProperty);

    xqProcessor = new Processor(false);
    xqCompiler = xqProcessor.newXQueryCompiler();
    // Doesn't work; seems to be a bug
    // xqCompiler.declareNamespace("", "http://www.w3.org/1999/xhtml"); //
    // default namespace
    // declare default element namespace "http://www.w3.org/1999/xhtml";

    // Works; it can be used to simplify the xqueries
    // declare namespace
    // java="java:org.disco.flow.analyzers.XQueryAnalyzer";
    // xqCompiler.declareNamespace("java",
    // "java:org.disco.flow.analyzers.XQueryAnalyzer");

    xqueries = new TreeMap<String, XQueryExecutable>();
    final File[] xqFiles = xqueriesHome.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".xq");
        }
    });
    for (File xqueryFile : xqFiles) {
        try {
            xqueries.put(xqueryFile.getName(), xqCompiler.compile(xqueryFile));
            log.debug("Loaded " + xqueryFile.getCanonicalPath());
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (SaxonApiException e) {
            e.printStackTrace();
        }
    }
}

From source file:functionaltests.matlab.AbstractMatlabTest.java

protected void init() throws Exception {

    mat_tb_home = new File(System.getProperty("pa.matlab.home")).getCanonicalFile();

    test_home = resourceToFile("RunUnitTest.m").getParentFile();

    credFile = new File(test_home, "demo.cred");

    schedURI = new URI(SchedulerTHelper.getLocalUrl());

    // delete all db files
    File[] dbJobFiles = new File(TMPDIR).listFiles(new FilenameFilter() {
        @Override/*from w w  w  .  java  2  s .com*/
        public boolean accept(File dir, String name) {
            if (name.startsWith(AOMatlabEnvironment.MIDDLEMAN_JOBS_FILE_NAME)) {
                return true;
            } else if (name.startsWith(MatlabTaskRepository.MATLAB_EMBEDDED_JOBS_FILE_NAME)) {
                return true;
                // TODO : change below the value to JobDB.DEFAULT_STATUS_FILENAME
            } else if (name.startsWith("SmartProxy")) {
                return true;
            }
            return false;
        }
    });

    for (File f : dbJobFiles) {
        try {
            System.out.println("Deleting " + f);
            f.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:ClassPath.java

/**
 * Checks for class path components in the following properties:
 * "java.class.path", "sun.boot.class.path", "java.ext.dirs"
 * //  w  ww .  ja  v a  2  s .  c  o  m
 * @return class path as used by default by BCEL
 */
public static final String getClassPath() {
    String class_path = System.getProperty("java.class.path");
    String boot_path = System.getProperty("sun.boot.class.path");
    String ext_path = System.getProperty("java.ext.dirs");
    List list = new ArrayList();
    getPathComponents(class_path, list);
    getPathComponents(boot_path, list);
    List dirs = new ArrayList();
    getPathComponents(ext_path, dirs);
    for (Iterator e = dirs.iterator(); e.hasNext();) {
        File ext_dir = new File((String) e.next());
        String[] extensions = ext_dir.list(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                name = name.toLowerCase(Locale.ENGLISH);
                return name.endsWith(".zip") || name.endsWith(".jar");
            }
        });
        if (extensions != null) {
            for (int i = 0; i < extensions.length; i++) {
                list.add(ext_dir.getPath() + File.separatorChar + extensions[i]);
            }
        }
    }
    StringBuffer buf = new StringBuffer();
    for (Iterator e = list.iterator(); e.hasNext();) {
        buf.append((String) e.next());
        if (e.hasNext()) {
            buf.append(File.pathSeparatorChar);
        }
    }
    return buf.toString().intern();
}

From source file:eu.annocultor.utils.OntologySubtractor.java

private static Collection<String> listNameStamsForFilesWithDeletedStatements(File sourceDir) {
    Set<String> stamms = new HashSet<String>();
    for (String file : sourceDir.list(new FilenameFilter() {

        @Override//from w  w  w . j  a  va 2 s.co  m
        public boolean accept(File dir, String name) {
            return name.endsWith(DELETED_RDF);
        }
    })) {
        String stam = StringUtils.substringBeforeLast(file, DELETED_RDF);
        // allow one word before: real.name.*.deleted.rdf
        stam = StringUtils.substringBeforeLast(stam, ".");
        stamms.add(stam);
    }
    return stamms;
}

From source file:eu.usrv.amdiforge.core.GraveFileHandler.java

public List<String> getMatchedDumps(World world, String prefix) {
    File saveFolder = getSaveFolder(world);
    final String actualPrefix = StringUtils.startsWithIgnoreCase(prefix, PREFIX) ? prefix : PREFIX + prefix;
    File[] files = saveFolder.listFiles(new FilenameFilter() {
        @Override/*from  www.  j  av  a  2 s  .  c o  m*/
        public boolean accept(File dir, String name) {
            return name.startsWith(actualPrefix);
        }
    });

    List<String> result = Lists.newArrayList();
    int toCut = PREFIX.length();

    for (File f : files) {
        String name = f.getName();
        result.add(name.substring(toCut, name.length() - 4));
    }

    return result;
}

From source file:functionaltests.workflow.TestJobLegacySchemas.java

private void prepareDataspaceFolder() throws IOException {
    File ds = new File(PAResourceManagerProperties.RM_HOME.getValueAsString(),
            "/scheduler/scheduler-server/build/JobLegacySchemas_dataspace");

    if (ds.exists()) {
        File[] filesToDelete = ds.listFiles(new FilenameFilter() {
            @Override/*from  www . ja  v  a  2  s .c  om*/
            public boolean accept(File dir, String name) {
                return name.startsWith("myfileout") || name.endsWith(".log");
            }
        });
        for (File f : filesToDelete) {
            FileUtils.forceDelete(f);
        }
    } else {
        FileUtils.forceMkdir(ds);
    }
}