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.addthis.hydra.task.map.DataPurgeServiceImpl.java

/**
 * recursively add subdirectories into the directoryList
 *//*from  ww w.  j av  a2  s.  c o m*/
protected List<File> getSubdirectoryList(File current, List<File> directoryList) {
    if (directoryList == null) {
        directoryList = new ArrayList<>();
    }
    directoryList.add(current);
    if (current.isDirectory()) {
        File[] fileArray = current.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isDirectory();
            }
        });
        if (fileArray != null) {
            for (File directory : fileArray) {
                getSubdirectoryList(directory, directoryList);
            }
        }
    }
    return directoryList;
}

From source file:net.yazilimsal.ldapserver.LdifLoader.java

/**
 * Load the existing LDIF files in alphabetic order
 *///from  w  w  w .j a v a  2  s  .c o  m
public void loadLdifs(DirectoryService directoryService, File ldifDirectory) throws Exception {

    // LOG and bail if property not set
    if (ldifDirectory == null) {
        LOG.info("LDIF load directory not specified.  No LDIF files will be loaded.");
        return;
    }

    // LOG and bail if LDIF directory does not exists
    if (!ldifDirectory.exists()) {
        LOG.warn("LDIF load directory '{}' does not exist.  No LDIF files will be loaded.",
                getCanonical(ldifDirectory));
        return;
    }

    ensureLdifFileBase(directoryService);

    // if ldif directory is a file try to load it
    if (ldifDirectory.isFile()) {
        if (LOG.isInfoEnabled()) {
            LOG.info("LDIF load directory '{}' is a file. Will attempt to load as LDIF.",
                    getCanonical(ldifDirectory));
        }

        try {
            loadLdif(directoryService, ldifDirectory);
        } catch (Exception ne) {
            // If the file can't be read, log the error, and stop
            // loading LDIFs.
            LOG.error(I18n.err(I18n.ERR_180, ldifDirectory.getAbsolutePath(), ne.getLocalizedMessage()));
            throw ne;
        }
    } else {
        // get all the ldif files within the directory
        File[] ldifFiles = ldifDirectory.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                boolean isLdif = Strings.toLowerCase(pathname.getName()).endsWith(".ldif");
                return pathname.isFile() && pathname.canRead() && isLdif;
            }
        });

        // LOG and bail if we could not find any LDIF files
        if ((ldifFiles == null) || (ldifFiles.length == 0)) {
            LOG.warn("LDIF load directory '{}' does not contain any LDIF files. No LDIF files will be loaded.",
                    getCanonical(ldifDirectory));
            return;
        }

        // Sort ldifFiles in alphabetic order
        Arrays.sort(ldifFiles, new Comparator<File>() {
            public int compare(File f1, File f2) {
                return f1.getName().compareTo(f2.getName());
            }
        });

        // load all the ldif files and load each one that is loaded
        for (File ldifFile : ldifFiles) {
            try {
                LOG.info("Loading LDIF file '{}'", ldifFile.getName());
                loadLdif(directoryService, ldifFile);
            } catch (Exception ne) {
                // If the file can't be read, log the error, and stop
                // loading LDIFs.
                LOG.error(I18n.err(I18n.ERR_180, ldifFile.getAbsolutePath(), ne.getLocalizedMessage()));
                throw ne;
            }
        }
    }
}

From source file:com.oakhole.Generate.java

/**
 * ?Entity/*ww  w  . j a  v a2 s  .  co  m*/
 * @param filePath
 * @param entities
 */
private void fetchEntities(String packageName, String filePath, Set<Class<?>> entities) {

    // package
    File file = new File(filePath);

    if (!file.exists() || !file.isDirectory()) {
        logger.warn("{} neither exists nor the directory .", filePath);
        return;
    }

    // ?packageclass
    File[] subFiles = file.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() || pathname.getName().endsWith(".class");
        }
    });

    for (File subFile : subFiles) {

        // ?class?
        if (subFile.isDirectory()) {
            fetchEntities(packageName + "." + subFile.getName(), subFile.getAbsolutePath(), entities);
        } else {
            // ??
            String className = subFile.getName().substring(0, subFile.getName().length() - 6);
            try {
                Class object = Thread.currentThread().getContextClassLoader()
                        .loadClass(packageName + "." + className);
                if (object.getAnnotation(Entity.class) != null) {
                    entities.add(object);
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.source.BrowserVersionFeaturesSource.java

/**
 * Reverses the specified {@link BrowserVersionFeatures} to the other browsers (by modifying only
 * the configuration files).//from  w w  w .  ja  va  2s  .c o m
 * For example, if it is currently defined in IE8 and FF3, the BrowserFeatures will be removed from those browsers
 * configurations and added to the others ones.
 *
 * This is useful if you have something like "!browserVersion.hasFeature()" and you need to reverse the condition.
 *
 * @param features the feature to reverse
 * @throws IOException if an error occurs
 */
public void reverse(final BrowserVersionFeatures features) throws IOException {
    final File propertiesFolder = new File(root_,
            "src/main/resources/com/gargoylesoftware/htmlunit/javascript/configuration");
    for (final File f : propertiesFolder.listFiles(new FileFilter() {
        public boolean accept(final File pathname) {
            return pathname.getName().endsWith(".properties");
        }
    })) {
        final List<String> list = FileUtils.readLines(f);
        final String name = features.name();
        if (list.contains(name)) {
            list.remove(name);
        } else {
            list.add(name);
        }
        Collections.sort(list);
        FileUtils.writeLines(f, list);
    }
}

From source file:com.devmaid.web.remotefs.RemoteFsVolume.java

@Override
public boolean hasChildFolder(FsItem fsi) {
    return asFile(fsi).isDirectory() && asFile(fsi).listFiles(new FileFilter() {
        @Override//w w w .j  a  v a2  s  .c  o m
        public boolean accept(java.io.File arg0) {
            return arg0.isDirectory();
        }
    }).length > 0;
}

From source file:com.jefftharris.passwdsafe.FileListFragment.java

/** Get the files in a directory */
private static FileData[] getFiles(File dir, final boolean showHiddenFiles,
        @SuppressWarnings("SameParameterValue") final boolean showDirs) {
    File[] files = dir.listFiles(new FileFilter() {
        public final boolean accept(File pathname) {
            String filename = pathname.getName();
            if (pathname.isDirectory()) {
                return showDirs && (showHiddenFiles
                        || !(filename.startsWith(".") || filename.equalsIgnoreCase("LOST.DIR")));
            }/*from  w  w  w . j  a va 2 s  . c  o m*/
            return filename.endsWith(".psafe3") || filename.endsWith(".dat")
                    || (showHiddenFiles && (filename.endsWith(".psafe3~") || filename.endsWith(".dat~")
                            || filename.endsWith(".ibak")));
        }
    });

    FileData[] data;
    if (files != null) {
        Arrays.sort(files, new FileComparator());
        data = new FileData[files.length];
        for (int i = 0; i < files.length; ++i) {
            data[i] = new FileData(files[i]);
        }
    } else {
        data = new FileData[0];
    }

    return data;
}

From source file:net.erdfelt.android.sdkfido.local.LocalAndroidPlatforms.java

private void loadPlatformsDir() throws IOException {
    File platformsDir = new File(this.homeDir, "platforms");
    if (!platformsDir.exists()) {
        LOG.warning("Directory does not exist: " + platformsDir);
        return;//from  w  w  w  .  j  av a 2s.c o m
    }

    File subdirs[] = platformsDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File path) {
            return path.isDirectory();
        }
    });

    for (File subdir : subdirs) {
        AndroidPlatform platform = loadPlatform(subdir);
        addPlatform(platform);
    }
}

From source file:org.apache.carbondata.sdk.file.CSVCarbonWriterTest.java

@Test
public void test2Block() throws IOException {
    String path = "./testWriteFiles";
    FileUtils.deleteDirectory(new File(path));

    Field[] fields = new Field[2];
    fields[0] = new Field("name", DataTypes.STRING);
    fields[1] = new Field("age", DataTypes.INT);

    TestUtil.writeFilesAndVerify(1000 * 1000, new Schema(fields), path, null, 2, 2);
    File[] dataFiles = new File(path).listFiles(new FileFilter() {
        @Override/*  ww  w  .  ja v  a 2 s. c o  m*/
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT);
        }
    });
    Assert.assertNotNull(dataFiles);
    Assert.assertEquals(2, dataFiles.length);

    FileUtils.deleteDirectory(new File(path));
}

From source file:com.mirth.connect.server.MirthWebServer.java

public MirthWebServer(PropertiesConfiguration mirthProperties) throws Exception {
    // this disables a "form too large" error for occuring by setting
    // form size to infinite
    System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "0");

    String baseAPI = "/api";
    boolean apiAllowHTTP = Boolean.parseBoolean(mirthProperties.getString("server.api.allowhttp", "false"));

    // add HTTP listener
    connector = new ServerConnector(this);
    connector.setName(CONNECTOR);//from  w w w. j  a  va 2  s . co m
    connector.setHost(mirthProperties.getString("http.host", "0.0.0.0"));
    connector.setPort(mirthProperties.getInt("http.port"));

    // add HTTPS listener
    sslConnector = createSSLConnector(CONNECTOR_SSL, mirthProperties);

    handlers = new HandlerList();
    String contextPath = mirthProperties.getString("http.contextpath", "");

    // Add a starting slash if one does not exist
    if (!contextPath.startsWith("/")) {
        contextPath = "/" + contextPath;
    }

    // Remove a trailing slash if one exists
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }

    // find the client-lib path
    String clientLibPath = null;

    if (ClassPathResource.getResourceURI("client-lib") != null) {
        clientLibPath = ClassPathResource.getResourceURI("client-lib").getPath() + File.separator;
    } else {
        clientLibPath = ControllerFactory.getFactory().createConfigurationController().getBaseDir()
                + File.separator + "client-lib" + File.separator;
    }

    // Create the lib context
    ContextHandler libContextHandler = new ContextHandler();
    libContextHandler.setContextPath(contextPath + "/webstart/client-lib");
    libContextHandler.setResourceBase(clientLibPath);
    libContextHandler.setHandler(new ResourceHandler());
    handlers.addHandler(libContextHandler);

    // Create the extensions context
    ContextHandler extensionsContextHandler = new ContextHandler();
    extensionsContextHandler.setContextPath(contextPath + "/webstart/extensions/libs");
    String extensionsPath = new File(ExtensionController.getExtensionsPath()).getPath();
    extensionsContextHandler.setResourceBase(extensionsPath);
    extensionsContextHandler.setHandler(new ResourceHandler());
    handlers.addHandler(extensionsContextHandler);

    // Create the public_html context
    ContextHandler publicContextHandler = new ContextHandler();
    publicContextHandler.setContextPath(contextPath);
    String publicPath = ControllerFactory.getFactory().createConfigurationController().getBaseDir()
            + File.separator + "public_html";
    publicContextHandler.setResourceBase(publicPath);
    publicContextHandler.setHandler(new ResourceHandler());
    handlers.addHandler(publicContextHandler);

    // Create the javadocs context
    ContextHandler javadocsContextHandler = new ContextHandler();
    javadocsContextHandler.setContextPath(contextPath + "/javadocs");
    String javadocsPath = ControllerFactory.getFactory().createConfigurationController().getBaseDir()
            + File.separator + "docs" + File.separator + "javadocs";
    javadocsContextHandler.setResourceBase(javadocsPath);
    ResourceHandler javadocsResourceHandler = new ResourceHandler();
    javadocsResourceHandler.setDirectoriesListed(true);
    javadocsContextHandler.setHandler(javadocsResourceHandler);
    handlers.addHandler(javadocsContextHandler);

    // Load all web apps dynamically
    webapps = new ArrayList<WebAppContext>();

    FileFilter filter = new FileFilter() {
        @Override
        public boolean accept(File file) {
            return file.getName().endsWith(".war");
        }
    };

    /*
     * If in an IDE, webapps will be on the classpath as a resource. If that's the case, use
     * that directory. Otherwise, use the mirth home directory and append webapps.
     */
    String webappsDir = null;
    if (ClassPathResource.getResourceURI("webapps") != null) {
        webappsDir = ClassPathResource.getResourceURI("webapps").getPath() + File.separator;
    } else {
        webappsDir = ControllerFactory.getFactory().createConfigurationController().getBaseDir()
                + File.separator + "webapps" + File.separator;
    }

    File[] listOfFiles = new File(webappsDir).listFiles(filter);

    if (listOfFiles != null) {
        // Since webapps may use JSP and JSTL, we need to enable the AnnotationConfiguration in order to correctly set up the JSP container.
        Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(this);
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
                "org.eclipse.jetty.annotations.AnnotationConfiguration");

        for (File file : listOfFiles) {
            logger.debug("webApp File Path: " + file.getAbsolutePath());

            WebAppContext webapp = new WebAppContext();
            webapp.setContextPath(contextPath + "/" + file.getName().substring(0, file.getName().length() - 4));

            /*
             * Set the ContainerIncludeJarPattern so that Jetty examines these JARs for TLDs,
             * web fragments, etc. If you omit the jar that contains the JSTL TLDs, the JSP
             * engine will scan for them instead.
             */
            webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                    ".*/[^/]*(javax\\.servlet-api|taglibs)[^/]*\\.jar$");

            logger.debug("webApp Context Path: " + webapp.getContextPath());

            webapp.setWar(file.getPath());
            handlers.addHandler(webapp);
            webapps.add(webapp);
        }
    }

    // Add Jersey API / swagger servlets for each specific version
    Version version = Version.getApiEarliest();
    while (version != null) {
        addApiServlets(handlers, contextPath, baseAPI, apiAllowHTTP, version);
        version = version.getNextVersion();
    }
    // Add servlets for the main (default) API endpoint
    addApiServlets(handlers, contextPath, baseAPI, apiAllowHTTP, null);

    // Create the webstart servlet handler
    ServletContextHandler servletContextHandler = new ServletContextHandler();
    servletContextHandler.setContextPath(contextPath);
    servletContextHandler.addFilter(new FilterHolder(new MethodFilter()), "/*",
            EnumSet.of(DispatcherType.REQUEST));
    servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart.jnlp");
    servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart");
    servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart/extensions/*");
    handlers.addHandler(servletContextHandler);

    // add the default handler for misc requests (favicon, etc.)
    DefaultHandler defaultHandler = new DefaultHandler();
    defaultHandler.setServeIcon(false); // don't serve the Jetty favicon
    handlers.addHandler(defaultHandler);

    setHandler(handlers);
    setConnectors(new Connector[] { connector, sslConnector });
}

From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java

public File[] returnFilesFoundBasedOnSuffix(String suffix) {

    final Pattern p = Pattern.compile(".*\\." + suffix);
    return TARGETDIR.listFiles(new FileFilter() {
        @Override/*from www  . j av  a  2s .  co m*/
        public boolean accept(File file) {
            return p.matcher(file.getName()).matches();
        }
    });
}