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:gov.nih.nci.ncicb.cadsr.bulkloader.CaDSRBulkLoadProcessor.java

private File[] getInputFiles(String inputDir) {
    final File inputDirFile = new File(inputDir);
    File[] inputFiles = inputDirFile.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (dir.getAbsolutePath().equalsIgnoreCase(inputDirFile.getAbsolutePath())
                    && name.endsWith(".xml")) {
                return true;
            }//from   w  w w .j a va2  s . c  om
            return false;
        }

    });

    return inputFiles;
}

From source file:ext.deployit.community.importer.zip.ZipImporter.java

@Override
public List<String> list(File directory) {
    FilenameFilter zipFileFilter = new FilenameFilter() {
        @Override//w ww.j a  v a 2s .c o m
        public boolean accept(File dir, String name) {
            return isZip(name);
        }
    };
    List<String> zipFiles = scanSubdirectories ? listRecursively(directory, zipFileFilter)
            : newArrayList(directory.list(zipFileFilter));
    sort(zipFiles);
    LOGGER.debug("Found ZIP files in package directory: {}", zipFiles);
    return zipFiles;
}

From source file:com.ecyrd.jspwiki.content.Exporter.java

protected void export(String dir) throws IOException {
    System.out.println(// w  ww.  ja v a  2 s .  c  om
            "Exporting a FileSystemProvider/RCSFileProvider/VersioningFileProvider compatible repository.");
    System.out.println(
            "This version does not export attributes, ACLs or attachments. Please use --properties for that.");

    File df = new File(dir);

    File[] pages = df.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(FileSystemProvider.FILE_EXT);
        }
    });

    exportDocumentHeader();

    for (File f : pages) {
        String pageName = f.getName();
        pageName = pageName.replace(".txt", "");
        exportPageHeader(pageName, "Main", "TBD", new Date(f.lastModified()), false);

        // File content

        FileInputStream in = new FileInputStream(f);
        exportProperty("wiki:content", FileUtil.readContents(in, "UTF-8"), STRING);
        in.close();

        exportPageFooter();
    }
    exportDocumentFooter();

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

From source file:de.fhg.iais.asc.sipmaker.SipMakerFileSearcher.java

private File[] getVersionFiles(File versionsPath) {
    return versionsPath.listFiles(new FilenameFilter() {
        @Override/*w  w w.  j av a2s  . c  o m*/
        public boolean accept(File dir, String name) {
            return name.endsWith(SUFFIX) && new File(dir, name).isFile();
        }
    });
}

From source file:com.nullwire.trace.ExceptionHandler.java

/**
 * Search for stack trace files./*from w w w .ja v a2 s.c  o  m*/
 * @return
 */
private static String[] searchForStackTraces() {
    File dir = new File(G.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".stacktrace" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");

        }
    };
    return dir.list(filter);
}

From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AbstractAlbumCoverFetcherThread.java

private void createFileNameFilter() {
    imageFilter = new FilenameFilter() {

        @Override//from  w  ww. ja  v  a  2s . c o  m
        public boolean accept(File dir, String filename) {
            if (filename == null) {
                return false;
            }
            String lowercase = filename.toLowerCase();
            if (lowercase.endsWith("cover.jpg") || lowercase.endsWith("cover.png")
                    || lowercase.endsWith("folder.png") || lowercase.endsWith("folder.jpg")
                    || lowercase.endsWith("albumart.png") || lowercase.endsWith("albumart.jpg")) {
                return true;
            }
            return false;
        }

    };
}

From source file:hudson.PluginManager.java

public PluginManager(ServletContext context) {
    this.context = context;
    // JSON binding needs to be able to see all the classes from all the plugins
    WebApp.get(context).setClassLoader(uberClassLoader);

    rootDir = new File(Hudson.getInstance().getRootDir(), "plugins");
    if (!rootDir.exists())
        rootDir.mkdirs();// ww w  .  j  a  v  a  2 s . c o  m

    loadBundledPlugins();

    File[] archives = rootDir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".hpi") // plugin jar file
                    || name.endsWith(".hpl"); // linked plugin. for debugging.
        }
    });

    if (archives == null) {
        LOGGER.severe(
                "Hudson is unable to create " + rootDir + "\nPerhaps its security privilege is insufficient");
        return;
    }

    strategy = createPluginStrategy();

    // load plugins from a system property, for use in the "mvn hudson-dev:run"
    List<File> archivesList = new ArrayList<File>(Arrays.asList(archives));
    String hplProperty = System.getProperty("hudson.bundled.plugins");
    if (hplProperty != null) {
        for (String hplLocation : hplProperty.split(",")) {
            File hpl = new File(hplLocation.trim());
            if (hpl.exists())
                archivesList.add(hpl);
            else
                LOGGER.warning("bundled plugin " + hplLocation + " does not exist");
        }
    }

    for (File arc : archivesList) {
        try {
            PluginWrapper p = strategy.createPluginWrapper(arc);
            plugins.add(p);
            if (p.isActive())
                activePlugins.add(p);
        } catch (IOException e) {
            failedPlugins.add(new FailedPlugin(arc.getName(), e));
            LOGGER.log(Level.SEVERE, "Failed to load a plug-in " + arc, e);
        }
    }

    for (PluginWrapper p : activePlugins.toArray(new PluginWrapper[activePlugins.size()]))
        try {
            strategy.load(p);
        } catch (IOException e) {
            failedPlugins.add(new FailedPlugin(p.getShortName(), e));
            LOGGER.log(Level.SEVERE, "Failed to load a plug-in " + p.getShortName(), e);
            activePlugins.remove(p);
            plugins.remove(p);
        }
}

From source file:info.jtrac.config.JtracConfigurer.java

private void configureJtrac() throws Exception {

    String jtracHome = null;//from  ww w .ja  v a 2s  .c o  m
    ClassPathResource jtracInitResource = new ClassPathResource("jtrac-init.properties");
    // jtrac-init.properties assumed to exist
    Properties props = loadProps(jtracInitResource.getFile());
    logger.info("found 'jtrac-init.properties' on classpath, processing...");
    jtracHome = props.getProperty("jtrac.home");
    if (jtracHome != null) {
        logger.info("'jtrac.home' property initialized from 'jtrac-init.properties' as '" + jtracHome + "'");
    }
    //======================================================================
    FilenameFilter ff = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.startsWith("messages_") && name.endsWith(".properties");
        }
    };
    File[] messagePropsFiles = jtracInitResource.getFile().getParentFile().listFiles(ff);
    String locales = "en";
    for (File f : messagePropsFiles) {
        int endIndex = f.getName().indexOf('.');
        String localeCode = f.getName().substring(9, endIndex);
        locales += "," + localeCode;
    }
    logger.info("locales available configured are '" + locales + "'");
    props.setProperty("jtrac.locales", locales);
    //======================================================================
    if (jtracHome == null) {
        logger.info(
                "valid 'jtrac.home' property not available in 'jtrac-init.properties', trying system properties.");
        jtracHome = System.getProperty("jtrac.home");
        if (jtracHome != null) {
            logger.info("'jtrac.home' property initialized from system properties as '" + jtracHome + "'");
        }
    }
    if (jtracHome == null) {
        logger.info(
                "valid 'jtrac.home' property not available in system properties, trying servlet init paramters.");
        jtracHome = servletContext.getInitParameter("jtrac.home");
        if (jtracHome != null) {
            logger.info("Servlet init parameter 'jtrac.home' exists: '" + jtracHome + "'");
        }
    }
    if (jtracHome == null) {
        jtracHome = System.getProperty("user.home") + "/.jtrac";
        logger.warn("Servlet init paramter  'jtrac.home' does not exist.  Will use 'user.home' directory '"
                + jtracHome + "'");
    }
    //======================================================================
    File homeFile = new File(jtracHome);
    if (!homeFile.exists()) {
        homeFile.mkdir();
        logger.info("directory does not exist, created '" + homeFile.getPath() + "'");
        if (!homeFile.exists()) {
            String message = "invalid path '" + homeFile.getAbsolutePath()
                    + "', try creating this directory first.  Aborting.";
            logger.error(message);
            throw new Exception(message);
        }
    } else {
        logger.info("directory already exists: '" + homeFile.getPath() + "'");
    }
    props.setProperty("jtrac.home", homeFile.getAbsolutePath());
    //======================================================================
    File attachmentsFile = new File(jtracHome + "/attachments");
    if (!attachmentsFile.exists()) {
        attachmentsFile.mkdir();
        logger.info("directory does not exist, created '" + attachmentsFile.getPath() + "'");
    } else {
        logger.info("directory already exists: '" + attachmentsFile.getPath() + "'");
    }
    File indexesFile = new File(jtracHome + "/indexes");
    if (!indexesFile.exists()) {
        indexesFile.mkdir();
        logger.info("directory does not exist, created '" + indexesFile.getPath() + "'");
    } else {
        logger.info("directory already exists: '" + indexesFile.getPath() + "'");
    }
    //======================================================================
    File propsFile = new File(homeFile.getPath() + "/jtrac.properties");
    if (!propsFile.exists()) {
        propsFile.createNewFile();
        logger.info("properties file does not exist, created '" + propsFile.getPath() + "'");
        OutputStream os = new FileOutputStream(propsFile);
        Writer out = new PrintWriter(os);
        try {
            out.write("database.driver=org.hsqldb.jdbcDriver\n");
            out.write("database.url=jdbc:hsqldb:file:${jtrac.home}/db/jtrac\n");
            out.write("database.username=sa\n");
            out.write("database.password=\n");
            out.write("hibernate.dialect=org.hibernate.dialect.HSQLDialect\n");
            out.write("hibernate.show_sql=false\n");
        } finally {
            out.close();
            os.close();
        }
        logger.info("HSQLDB will be used.  Finished creating '" + propsFile.getPath() + "'");
    } else {
        logger.info("'jtrac.properties' file exists: '" + propsFile.getPath() + "'");
    }
    //======================================================================
    String version = "0.0.0";
    String timestamp = "0000";
    ClassPathResource versionResource = new ClassPathResource("jtrac-version.properties");
    if (versionResource.exists()) {
        logger.info("found 'jtrac-version.properties' on classpath, processing...");
        Properties versionProps = loadProps(versionResource.getFile());
        version = versionProps.getProperty("version");
        timestamp = versionProps.getProperty("timestamp");
    } else {
        logger.info("did not find 'jtrac-version.properties' on classpath");
    }
    logger.info("jtrac.version = '" + version + "'");
    logger.info("jtrac.timestamp = '" + timestamp + "'");
    props.setProperty("jtrac.version", version);
    props.setProperty("jtrac.timestamp", timestamp);
    props.setProperty("database.validationQuery", "SELECT 1");
    props.setProperty("ldap.url", "");
    props.setProperty("ldap.activeDirectoryDomain", "");
    props.setProperty("ldap.searchBase", "");
    props.setProperty("database.datasource.jndiname", "");
    // set default properties that can be overridden by user if required
    setProperties(props);
    // finally set the property that spring is expecting, manually
    FileSystemResource fsr = new FileSystemResource(propsFile);
    setLocation(fsr);
}

From source file:Neo4JDataImporter.java

private static void doImport(GraphDatabaseService graphdb) throws Exception {
    //        IndexManager index = graphdb.index();
    //        Index<Node> actors = index.forNodes( "actors" );
    //        actors.add( fishburn, "name", fishburn.getProperty( "name" ) );

    //       importData(graphdb);
    // add some data first
    File dir = new File("ideas/src/main/resources/device-xml");

    Node root = createRootNetworkNode(graphdb);
    File[] files = dir.listFiles(new FilenameFilter() {
        @Override/*from   w  w w. j  a v a 2s . co  m*/
        public boolean accept(File dir, String name) {
            return name.endsWith(".xml");
        }
    });

    long start = System.currentTimeMillis();
    //        importData(graphdb, root, new File(dir, "device-data-MAG-112-1.xml"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Press enter to continue");
    //        reader.readLine();
    for (File file : files) {
        System.out.println("importing file: " + file.getName());
        importData(graphdb, root, file);
        System.out.println("Press enter to continue");
        //            reader.readLine();
        Thread.sleep(300);
    }
    System.out.println("Created nodes: " + nodeCounter);
    System.out.println("Imported ... " + (System.currentTimeMillis() - start) / 1000 + " seconds");
}