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.twinsoft.convertigo.engine.util.ProjectUtils.java

public static void copyIndexFile(String projectName) throws Exception {
    String projectRoot = Engine.PROJECTS_PATH + '/' + projectName;
    String templateBase = Engine.TEMPLATES_PATH + "/base";
    File indexPage = new File(projectRoot + "/index.html");
    if (!indexPage.exists()) {
        if (new File(projectRoot + "/sna.xsl").exists()) { /** webization javelin */
            if (new File(projectRoot + "/templates/status.xsl").exists()) /** not DKU / DKU */
                FileUtils.copyFile(new File(templateBase + "/index_javelin.html"), indexPage);
            else// ww  w  .j  a v a2  s  .  c o m
                FileUtils.copyFile(new File(templateBase + "/index_javelinDKU.html"), indexPage);
        } else {
            FileFilter fileFilterNoSVN = new FileFilter() {
                public boolean accept(File pathname) {
                    String name = pathname.getName();
                    return !name.equals(".svn") || !name.equals("CVS");
                }
            };
            FileUtils.copyFile(new File(templateBase + "/index.html"), indexPage);
            FileUtils.copyDirectory(new File(templateBase + "/js"), new File(projectRoot + "/js"),
                    fileFilterNoSVN);
            FileUtils.copyDirectory(new File(templateBase + "/css"), new File(projectRoot + "/css"),
                    fileFilterNoSVN);
        }
    }
}

From source file:com.citrixonline.android.utils.LocalAndroidSdk.java

public File lastFolderModified(File dir) {
    File[] files = dir.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }//from   w ww  .  ja  v  a2s.c  o m
    });
    long lastMod = Long.MIN_VALUE;
    File choice = null;
    for (File file : files) {
        if (file.lastModified() > lastMod) {
            choice = file;
            lastMod = file.lastModified();
        }
    }
    return choice;
}

From source file:br.com.fabiopereira.quebrazip.JavaZipSplitter.java

private static void join() {
    try {// ww  w.jav  a 2  s .com
        // Escrevendo para simular
        File folder = new File(ORIGEM_PATH);
        File[] files = folder.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return !file.getName().endsWith(".zip");
            }
        });
        List<File> fileList = new ArrayList<File>();
        for (File file : files) {
            fileList.add(file);
        }
        Collections.sort(fileList, new Comparator<File>() {
            public int compare(File f1, File f2) {
                int i1 = Integer.parseInt(f1.getName().substring(f1.getName().indexOf(".txt") + 4));
                int i2 = Integer.parseInt(f2.getName().substring(f2.getName().indexOf(".txt") + 4));
                if (i1 == i2) {
                    return 0;
                }
                return i1 < i2 ? -1 : 1;
            };
        });
        // Obtendo tamanho total
        int sizeTotal = 0;
        for (File file : fileList) {
            sizeTotal += file.length();
        }
        byte[] tudao = new byte[sizeTotal];
        int posicao = 0;
        for (File file : fileList) {
            byte[] b = FileUtils.readFileToByteArray(file);
            invertArrayBytes(b);
            int i = 0;
            for (i = posicao; i < posicao + b.length; i++) {
                tudao[i] = (b[i - posicao]);
            }
            posicao = i;
        }
        FileUtils.writeByteArrayToFile(new File(ORIGEM_PATH + "/result.zip"), tudao);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.excalibur.discovery.jackson.databind.test.JsonYamlObjectMapperTest.java

private Applications createApplications() {
    String defaultPath = "~/sequences";
    File[] files = new File(dir).listFiles(new FileFilter() {
        @Override/*  w  w  w.j ava 2s . c o m*/
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".fasta");
        }
    });

    Applications applications = new Applications();

    for (File file : files) {
        String name = file.getName();
        Application ssearch36 = new Application()
                .setCommandLine("ssearch36 -d 0 ${query} ${library_file} >> ${score_table}")
                .setName("ssearch36");
        ssearch36.setId(UUID.randomUUID().toString());
        ssearch36.addData(new AppData().setGenerated(YesNoEnum.NO).setName("query")
                .setPath(String.format("%s/%s", defaultPath, file.getName())));
        ssearch36.addData(new AppData().setGenerated(YesNoEnum.NO).setName("library_file")
                .setPath("~/uniprot_sprot.fasta"));
        ssearch36.addData(new AppData().setGenerated(YesNoEnum.YES).setName("score_table")
                .setPath(String.format("~/scores/%s_scores.txt", name)));

        applications.add(ssearch36);
    }
    return applications;
}

From source file:com.ning.metrics.eventtracker.TestInvalidPayload.java

private File[] listBinFiles(final File dir) {
    return dir.listFiles(new FileFilter() {
        @Override//  w w w  . ja  v a 2 s  . co  m
        public boolean accept(final File pathname) {
            return pathname.getName().endsWith(".bin");
        }
    });
}

From source file:com.twosigma.beaker.core.module.elfinder.impl.localfs.LocalFsVolume.java

@Override
public boolean hasChildFolder(FsItem fsi) {
    File file = asFile(fsi);/*  w w  w. ja  v  a2  s  .c  om*/
    File[] listFiles = file.listFiles(new FileFilter() {

        @Override
        public boolean accept(File arg0) {
            return arg0.isDirectory();
        }
    });
    return file.isDirectory() && listFiles != null && listFiles.length > 0;
}

From source file:com.bstek.dorado.console.system.log.file.FileReaderController.java

@Expose
public Collection<String> getFileNameList() throws IOException {
    String dir = FileReaderController.getLogDirectoryPath();
    List<String> nameList = new ArrayList<String>();
    if (StringUtils.isEmpty(dir)) {
        return nameList;
    }// w w w .ja v a 2  s.c om
    File file = new File(dir);

    File[] files = file.listFiles(new FileFilter() {
        public boolean accept(File tmpFile) {
            if (!tmpFile.isDirectory()) {
                return true;
            }
            return false;
        }
    });

    for (int i = 0; i < files.length; i++) {
        nameList.add(files[i].getName());
    }

    return nameList;

}

From source file:functionaltests.dataspaces.TestDataspaceConcurrentTransfer.java

@Test
public void multiple_tasks_transferring() throws Throwable {
    Job job = createJobWithFileTransfers();

    JobId id = schedulerHelper.testJobSubmission(job);
    assertFalse(/*w  w w  . ja  v  a  2s.co m*/
            "The job execution must not fail, check the node source log file : Node-local-" + JOB_NAME + ".log",
            schedulerHelper.getJobResult(id).hadException());

    File[] inputDirectories = globalSpaceFile.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith(FOLDER_IN_NAME);
        }
    });

    File[] outputDirectories = globalSpaceFile.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith(FOLDER_OUT_NAME);
        }
    });

    Assert.assertEquals(NB_TASKS, inputDirectories.length);
    Assert.assertEquals(NB_TASKS, outputDirectories.length);

    HashMap<String, File> directoriesMap = new HashMap<>();

    for (File dir : inputDirectories) {
        directoriesMap.put(dir.getName(), dir);
    }

    for (File dir : outputDirectories) {
        directoriesMap.put(dir.getName(), dir);
    }

    for (int i = 0; i < NB_TASKS; i++) {
        File inputDir = directoriesMap.get(FOLDER_IN_NAME + i);
        assertNotNull(inputDir);
        File inputFile = new File(inputDir, FILE_NAME + i + FILE_EXT_IN);
        Assert.assertTrue(inputFile.exists());

        File outputDir = directoriesMap.get(FOLDER_OUT_NAME + i);
        assertNotNull(outputDir);
        File outputFile = new File(outputDir, FILE_NAME + i + FILE_EXT_OUT);
        Assert.assertTrue(outputFile.exists());
    }
}

From source file:com.clank.launcher.Launcher.java

/**
 * Delete old extracted files.//w w w.  java2  s.co  m
 */
public void cleanupExtractDir() {
    log.info("Cleaning up temporary extracted files directory...");

    final long now = System.currentTimeMillis();

    File[] dirs = getExtractDir().listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            try {
                long time = Long.parseLong(pathname.getName());
                return (now - time) > (1000 * 60 * 60);
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    if (dirs != null) {
        for (File dir : dirs) {
            log.info("Removing " + dir.getAbsolutePath() + "...");
            try {
                FileUtils.deleteDirectory(dir);
            } catch (IOException e) {
                log.log(Level.WARNING, "Failed to delete " + dir.getAbsolutePath(), e);
            }
        }
    }
}

From source file:org.powertac.producer.ProducerService.java

/**
 * This function de-serializes the producers into objects and returns a list
 * with the resulting objects/*from w w  w .  j a  v  a  2s.co  m*/
 * 
 * @return
 * @throws IOException
 */
protected List<Producer> loadProducers() throws IOException {
    List<Producer> producers = new ArrayList<Producer>();

    // filters the xml files
    FileFilter filter = new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            String name = pathname.toString().toLowerCase();
            if (pathname.isFile() && name.endsWith(".xml")) {
                return true;
            }
            return false;
        }
    };

    // Help xstream understand the xml files
    XStream xstream = new XStream();
    xstream.processAnnotations(SteamPlant.class);
    xstream.processAnnotations(Dam.class);
    xstream.processAnnotations(RunOfRiver.class);
    xstream.processAnnotations(HydroBase.class);
    xstream.processAnnotations(WindFarm.class);
    xstream.processAnnotations(WindTurbine.class);
    xstream.processAnnotations(SolarFarm.class);
    xstream.processAnnotations(PvPanel.class);
    xstream.processAnnotations(Producer.class);

    // this loads the default producers
    if (producerFileFolder == null) {
        for (String name : defaultProducers) {
            InputStream stream = ProducerService.class.getResourceAsStream(name);
            Producer producer = (Producer) xstream.fromXML(stream);
            producers.add(producer);
            stream.close();
        }
        return producers;
    }

    File confFolder = new File(this.producerFileFolder);
    if (!confFolder.isDirectory() || !confFolder.exists()) {
        // folder is wrong return an empty array
        log.error("The supplied configuration path was invalid.");
    } else {
        // iterate over all the files and dererialize them
        for (File conf : confFolder.listFiles(filter)) {
            String name = conf.toString().toLowerCase();
            if (name.contains("steam") || name.contains("dam") || name.contains("river")
                    || name.contains("solar") || name.contains("wind")) {
                Producer producer = (Producer) xstream.fromXML(conf);
                producers.add(producer);
            }
        }
    }
    return producers;
}