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:org.apache.falcon.util.HdfsClassLoader.java

private static List<URL> getJarsInPath(URL fileURL) throws MalformedURLException {
    List<URL> urls = new ArrayList<URL>();

    File file = new File(fileURL.getPath());
    if (file.isDirectory()) {
        File[] jarFiles = file.listFiles(new FileFilter() {
            @Override//from   w  ww  .  j a  v a2 s . co  m
            public boolean accept(File file) {
                return file.isFile() && file.getName().endsWith(".jar");
            }
        });

        for (File jarFile : jarFiles) {
            urls.add(jarFile.toURI().toURL());
        }

        if (!fileURL.toString().endsWith("/")) {
            fileURL = new URL(fileURL.toString() + "/");
        }
    }

    urls.add(fileURL);
    return urls;
}

From source file:it.digitalhumanities.dhcpublisher.DHCPublisher.java

private void unzip(String dhcDirName, String targetDirName) throws IOException {
    File dhcDir = new File(dhcDirName);
    if (!dhcDir.exists()) {
        throw new IllegalArgumentException(dhcDirName + " does not exist!");
    }/*  ww w  .  j  a v  a 2  s.  c om*/

    File targetDir = new File(targetDirName);
    if (!targetDir.exists()) {
        targetDir.mkdirs();
    }

    File[] dhcFiles = dhcDir.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isFile();
        }
    });
    int counter = 0;
    for (File file : dhcFiles) {
        counter++;
        System.out.println("Unzipping " + counter + ". file " + file + "...");
        try {
            unzipFile(counter, file, targetDir);
            System.out.println("Unzip for " + counter + ". file " + file + " done.");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("unable to unzip " + file);
        }
    }
}

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

@Test
public void compareAssets() throws IOException {
    File expectedImages = new File(expectedOutputDir, RodimusCli.IMAGE_DIR_NAME);
    File actualImages = new File(actualOutputDir, RodimusCli.IMAGE_DIR_NAME);

    assertEquals("Image directories don't match.", expectedImages.exists(), actualImages.exists());

    if (!expectedImages.exists() || expectedImages.list().length == 0) {
        assertTrue("Images produced when none expected!",
                !actualImages.exists() || actualImages.list().length == 0);
        return;//  w ww.jav  a 2  s  .  c  o m
    }

    for (File expected : expectedImages.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isFile();
        }
    })) {
        File actual = new File(actualImages, expected.getName());
        if (!actual.exists() && actual.isFile()) {
            fail("The file " + actual + " does not exist, or is not a file.");
        }
        if (!FileUtils.contentEquals(expected, actual)) {
            fail("The content in " + actual + " is different than " + expected);
        }
    }
}

From source file:de.peran.dependency.ChangedTestClassesHandler.java

private void updateDependenciesOnce(final String testClassName, final String testMethodName,
        final File parent) {
    LOG.debug("Parent: " + parent);
    final File[] listFiles = parent.listFiles(new FileFilter() {
        @Override// w  w  w  .ja v  a 2 s .  com
        public boolean accept(final File pathname) {
            return pathname.getName().matches("[0-9]*");
        }
    });
    LOG.debug("Kieker-Dateien: {}", listFiles.length);
    final File kiekerAllFolder = listFiles[0];
    LOG.debug("Analysiere Ordner: {} {}", kiekerAllFolder.getAbsolutePath(), testMethodName);
    final File kiekerNextFolder = new File(kiekerAllFolder, testMethodName);
    final File kiekerResultFolder = kiekerNextFolder.listFiles()[0];
    LOG.debug("Test: " + testMethodName);

    final PrintStream out = System.out;
    final PrintStream err = System.err;

    final File kiekerOutputFile = new File(projectFolder.getParent(), "ausgabe_kieker.txt");
    Map<String, Set<String>> calledClasses = null;
    try {
        System.setOut(new PrintStream(kiekerOutputFile));
        System.setErr(new PrintStream(kiekerOutputFile));
        calledClasses = new CalledMethodLoader(kiekerResultFolder).getCalledMethods();
        for (final Iterator<String> iterator = calledClasses.keySet().iterator(); iterator.hasNext();) {
            final String clazz = iterator.next();
            final String onlyClass = clazz.substring(clazz.lastIndexOf(".") + 1);
            final Collection<File> files = FileUtils.listFiles(projectFolder,
                    new WildcardFileFilter(onlyClass + "*"), TrueFileFilter.INSTANCE);
            if (files.size() == 0) {
                iterator.remove();
            }
        }
    } catch (final FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        System.setOut(out);
        System.setErr(err);
    }

    LOG.debug("Test: {} {}", testClassName, testMethodName);
    LOG.debug("Kieker: {} Dependencies: {}", kiekerResultFolder.getAbsolutePath(), calledClasses.size());
    final Map<String, Set<String>> dependencies = this.dependencies
            .getDependenciesForTest(testClassName + "." + testMethodName);
    dependencies.putAll(calledClasses);
}

From source file:com.github.snowdream.android.apps.imageviewer.ImageViewerActivity.java

public void initData() {
    imageLoader = ImageLoader.getInstance();
    imageUrls = new ArrayList<String>();

    Intent intent = getIntent();//ww w.ja v  a  2  s  . co m
    if (intent != null) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            imageUrls = bundle.getStringArrayList(Extra.IMAGES);
            imagePosition = bundle.getInt(Extra.IMAGE_POSITION, 0);
            imageMode = bundle.getInt(Extra.IMAGE_MODE, 0);
            Log.i("The snowdream bundle path of the image is: " + imageUri);
        }

        Uri uri = (Uri) intent.getData();
        if (uri != null) {
            imageUri = uri.getPath();
            fileName = uri.getLastPathSegment();
            getSupportActionBar().setSubtitle(fileName);
            Log.i("The path of the image is: " + imageUri);

            File file = new File(imageUri);

            imageUri = "file://" + imageUri;
            File dir = file.getParentFile();
            if (dir != null) {
                FileFilter fileFilter = new FileFilter() {
                    @Override
                    public boolean accept(File f) {
                        if (f != null) {
                            String extension = MimeTypeMap
                                    .getFileExtensionFromUrl(Uri.encode(f.getAbsolutePath()));
                            if (!TextUtils.isEmpty(extension)) {
                                String mimeType = MimeTypeMap.getSingleton()
                                        .getMimeTypeFromExtension(extension);
                                if (!TextUtils.isEmpty(mimeType) && mimeType.contains("image")) {
                                    return true;
                                }
                            }
                        }
                        return false;
                    }
                };

                File[] files = dir.listFiles(fileFilter);

                if (files != null && files.length > 0) {
                    int size = files.length;

                    for (int i = 0; i < size; i++) {
                        imageUrls.add("file://" + files[i].getAbsolutePath());
                    }
                    imagePosition = imageUrls.indexOf(imageUri);
                    imageMode = 1;
                    Log.i("Image Position:" + imagePosition);
                }

            } else {
                imageUrls.add("file://" + imageUri);
                imagePosition = 0;
                imageMode = 0;
            }
        }
    }

    else

    {
        Log.w("The intent is null!");
    }

}

From source file:com.mkl.websuites.internal.tests.ScenarioFolderTest.java

protected List<Test> processScenarioFilesInFolder(String folderPath) {

    File folder = new File(folderPath);

    if (!folder.exists()) {
        throw new WebServiceException(String.format(
                "Specified root folder in @Folder(path='%s') does not exist " + "(actual path is '%s')",
                folderPath, folder.getAbsolutePath()));
    }/*from  www. j  av a 2s .c  om*/

    ScenarioFileProcessor scenarioFileProcessor = ServiceFactory.get(ScenarioFileProcessor.class);

    File[] scenarioFiles = folder.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.getName().toLowerCase(Locale.getDefault()).endsWith(".scn");
        }
    });

    if (scenarioFiles == null) {
        throw new WebServiceException(String.format(
                "Error while reading scenario files in "
                        + "the folder path '%s'. Probably there is something wrong in the path string.",
                folderPath));
    }

    sort(scenarioFiles);

    List<Test> testsInThisFolder = new ArrayList<Test>();

    for (File scnearioFile : scenarioFiles) {

        List<Test> testsInScenarioFile = scenarioFileProcessor
                .processSingleScenarioFile(scnearioFile.getAbsolutePath());

        testsInThisFolder.addAll(testsInScenarioFile);
    }

    return testsInThisFolder;
}

From source file:com.bluexml.side.util.deployer.war.DirectWebAppsDeployer.java

public FileFilter getFileFilter(final DeployMode mode) {
    FileFilter incrementalFileFilter = new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.isFile()) {
                try {
                    String fileExt = FileHelper.getFileExt(pathname);
                    if (fileExt.equals(packageExt)) {
                        // test if package is newer than the deployed webapp
                        if (cleanned || !incremental || mode.equals(DeployMode.CUSTOM)) {
                            return true;
                        } else {
                            // incremental allowed
                            long module = pathname.lastModified();
                            File deployedWebbAppFolder = getIncrementalLastDeployedFlag();
                            long webapp = deployedWebbAppFolder.lastModified();

                            if (module > webapp) {
                                System.out.println("module is newer ");
                                // module must be deployed
                                return true;
                            } else {
                                System.out.println("module skipped by incremental deployer :" + pathname);
                                Date dateModule = new Date(module);
                                Date dateWebapp = new Date(webapp);
                                System.out.println("module :" + pathname + "[" + dateModule + "]");
                                System.out.println("webapp :" + deployedWebbAppFolder + "[" + dateWebapp + "]");
                            }/*  w  w w .  j ava 2  s.c  o  m*/
                        }
                    }

                } catch (Exception e) {
                    System.out.println("fileName :" + pathname);
                    e.printStackTrace();
                }
            }

            return false;
        }
    };

    return incrementalFileFilter;
}

From source file:com.runwaysdk.business.generation.AbstractCompiler.java

/**
 * Creates the Arguments object and sets the default values
 *///from w  w w .  j  a  va  2  s.  c o  m
protected AbstractCompiler() {
    // Ensure existence of some paths we're going to need
    ensureExistence(LocalProperties.getSrcRoot());
    ensureExistence(LocalProperties.getGenRoot());
    ArrayList<String> props = new ArrayList<String>();
    if (!ensureExistence(LocalProperties.getCommonSrc())) {
        props.add("common.src");
    }
    if (!ensureExistence(LocalProperties.getClientSrc())) {
        props.add("client.src");
    }
    if (!ensureExistence(LocalProperties.getServerSrc())) {
        props.add("server.src");
    }
    if (!ensureExistence(LocalProperties.getClientGenSrc())) {
        props.add("client.gen.src");
    }
    if (!ensureExistence(LocalProperties.getCommonGenSrc())) {
        props.add("common.gen.src");
    }
    if (!ensureExistence(LocalProperties.getServerGenSrc())) {
        props.add("server.gen.src");
    }
    if (!ensureExistence(LocalProperties.getClientGenBin())) {
        props.add("client.gen.bin");
    }
    if (!ensureExistence(LocalProperties.getCommonGenBin())) {
        props.add("common.gen.bin");
    }
    if (!ensureExistence(LocalProperties.getServerGenBin())) {
        props.add("server.gen.bin");
    }
    if (props.size() != 0) {
        throw new RunwayConfigurationException("Unable to generate source. Required configuration properties ["
                + StringUtils.join(props, ", ") + "] in local.properties do not exist.");
    }

    FileFilter fileFilter = new FileFilter() {
        public boolean accept(File pathname) {
            if (pathname.getAbsolutePath().endsWith(".jar") || pathname.isDirectory()) {
                return true;
            } else {
                return false;
            }
        }
    };

    arguments = new Arguments();

    arguments.common.setDestination(LocalProperties.getCommonGenBin());

    // Add all of the custom classpath entries
    for (String path : LocalProperties.getLocalClasspath()) {
        arguments.common.addClasspath(path);
    }

    // We need to add the runway to the classpath, either in a jar or directly
    if (LocalProperties.isRunwayEnvironment()) {
        // Check to make sure Runway is compiled, otherwise we get an unhelpful
        // error.
        ArrayList<String> uncompiled = new ArrayList<String>();
        File commonClass = new File(
                RunwayProperties.getRunwayCommonBin() + "/com/runwaysdk/business/BusinessDTO.class");
        if (!commonClass.exists()) {
            uncompiled.add("runwaysdk-common");
        }

        File clientClass = new File(
                RunwayProperties.getRunwayClientBin() + "/com/runwaysdk/controller/DTOFacade.class");
        if (!clientClass.exists()) {
            uncompiled.add("runwaysdk-client");
        }

        File serverClass = new File(
                RunwayProperties.getRunwayServerBin() + "/com/runwaysdk/business/Business.class");
        if (!serverClass.exists()) {
            uncompiled.add("runwaysdk-server");
        }

        if (uncompiled.size() > 0) {
            throw new CoreException(
                    "This project has declared a runway environment, yet the following runway projects have not been compiled ["
                            + StringUtils.join(uncompiled, ", ")
                            + "]. First compile these projects, then try your operation again.");
        }

        arguments.common.addClasspath(RunwayProperties.getRunwayCommonBin());
        arguments.server.addClasspath(RunwayProperties.getRunwayServerBin());
        arguments.client.addClasspath(RunwayProperties.getRunwayClientBin());
        arguments.common.addClasspath(LocalProperties.getLocalBin());
    } else if (!LocalProperties.useMavenLib()) {
        arguments.common.addClasspath(runwaysdkCommonJarPath);
        arguments.server.addClasspath(runwaysdkServerJarPath);
        arguments.client.addClasspath(runwaysdkClientJarPath);
    }

    // application environments have static classes that must be compiled
    // with the metadata generated classes.
    if (LocalProperties.isDevelopEnvironment()) {
        String localBin = LocalProperties.getLocalBin();
        if (localBin != null) {
            arguments.common.addClasspath(localBin);
        }

        arguments.common.addSourceDir(LocalProperties.getCommonSrc());
        arguments.client.addSourceDir(LocalProperties.getClientSrc());
        arguments.server.addSourceDir(LocalProperties.getServerSrc());
    }

    // Add the Project's Dependency Classpath
    if (!LocalProperties.useMavenLib()) {
        for (File lib : FileIO.listFilesRecursively(new File(LocalProperties.getCommonLib()), fileFilter)) {
            arguments.common.addClasspath(lib.getAbsolutePath());
        }
        for (File lib : FileIO.listFilesRecursively(new File(LocalProperties.getClientLib()), fileFilter)) {
            arguments.client.addClasspath(lib.getAbsolutePath());
        }
        for (File lib : FileIO.listFilesRecursively(new File(LocalProperties.getServerLib()), fileFilter)) {
            arguments.server.addClasspath(lib.getAbsolutePath());
        }
    } else {
        List<String> commonClasspath;
        List<String> clientClasspath;
        List<String> serverClasspath;

        commonClasspath = CommonProperties.getCommonClasspath();
        serverClasspath = ServerProperties.getServerClasspath();

        clientClasspath = ServerProperties.getClientClasspath();
        if (clientClasspath == null) {
            logger.warn("Unable to compile client, client jar not on classpath.");
            canCompileClient = false;
        } else {
            Iterator<String> clI = clientClasspath.iterator();
            while (clI.hasNext()) {
                arguments.client.addClasspath(clI.next());
            }
        }

        Iterator<String> cI = commonClasspath.iterator();
        while (cI.hasNext()) {
            arguments.common.addClasspath(cI.next());
        }
        Iterator<String> sI = serverClasspath.iterator();
        while (sI.hasNext()) {
            arguments.server.addClasspath(sI.next());
        }
    }

    arguments.common.addClasspath(LocalProperties.getCommonGenBin());
    if (LocalProperties.isDeployedInContainer()) {
        String containerLib = DeployProperties.getContainerLib();
        if (containerLib != null && !containerLib.equals("") && new File(containerLib).exists()) {
            for (File lib : FileIO.listFilesRecursively(new File(containerLib), fileFilter)) {
                arguments.common.addClasspath(lib.getAbsolutePath());
            }
        } else {
            String servletAPI = DeployProperties.getContainerServletAPIJarLocation();
            if (servletAPI != null && !servletAPI.equals("") && new File(servletAPI).exists()) {
                logger.warn(
                        "The deploy.properties configuration option 'deploy.servlet.jar' is deprecated in favor of 'container.lib'");
                arguments.common.addClasspath(servletAPI);
            } else {
                logger.error(
                        "Unable to add provided container jars to compilation classpath, deploy.properties configuration key 'container.lib' either does not exist or points to a file/directory that does not exist. This is likely to cause the compilation to fail.");
            }
        }
    }

    arguments.client.setDestination(LocalProperties.getClientGenBin());
    arguments.client.addClasspath(LocalProperties.getClientGenBin());
    arguments.client.setDependency(arguments.common);

    arguments.server.setDestination(LocalProperties.getServerGenBin());
    arguments.server.addClasspath(LocalProperties.getServerGenBin());
    arguments.server.setDependency(arguments.common);
}

From source file:org.eclipse.virgo.ide.runtime.internal.core.Server20Handler.java

/**
 * {@inheritDoc}/* ww w . j  a  va 2 s . c om*/
 */
public List<IRuntimeClasspathEntry> getRuntimeClasspath(IPath installPath) {
    List<IRuntimeClasspathEntry> cp = new ArrayList<IRuntimeClasspathEntry>();

    IPath binPath = installPath.append("lib");
    if (binPath.toFile().exists()) {
        File libFolder = binPath.toFile();
        for (File library : libFolder.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isFile() && pathname.toString().endsWith(".jar");
            }
        })) {
            IPath path = binPath.append(library.getName());
            cp.add(JavaRuntime.newArchiveRuntimeClasspathEntry(path));
        }
    }

    return cp;
}

From source file:com.mtgi.analytics.XmlBehaviorEventPersisterImpl.java

/**
 * JMX operation to list archived xml data files available for download.
 *///from  w  w w  . jav  a 2 s.c  o m
@ManagedOperation(description = "List all archived performance data log files available for download")
public StringBuffer listLogFiles() {

    final Pattern pattern = getArchiveNamePattern();

    //scan parent directory for matches.
    File[] files = file.getParentFile().listFiles(new FileFilter() {
        public boolean accept(File child) {
            String childName = child.getName();
            return pattern.matcher(childName).matches();
        }
    });
    Arrays.sort(files, FileOrder.INST);

    StringBuffer ret = new StringBuffer(
            "<html><body><table><tr><th>File</th><th>Size</th><th>Modified</th></tr>");
    for (File f : files)
        ret.append("<tr><td>").append(f.getName()).append("</td><td>").append(f.length()).append("</td><td>")
                .append(new Date(f.lastModified()).toString()).append("</td></tr>");
    ret.append("</table></body></html>");
    return ret;
}