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:eu.digitisation.idiomaident.utils.CorpusFilter.java

public static void filter(File in, File out, String refLanguage) {
    actualFile = new HashMap<>();

    //first obtain the list of language folders
    folderList = getFolderList(in);//  w w w.j  a  v  a 2 s  .  c om

    //foreach file in the folder of the reference language        
    //Last, we search for this word in the others language and if occurs in almost all
    //remove all occurrences (personal names).
    File refLangFolder = folderList.get(refLanguage);

    File[] filesInFolder = refLangFolder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File file, String name) {
            return name.endsWith(".txt");
        }
    });

    int num = 0;
    for (File textFile : filesInFolder) {
        String fileName = textFile.getName();
        actualFile.clear();
        num++;
        System.out.println("Processing " + num + " of " + filesInFolder.length);

        try {
            //First we populate the actualFile hashmap with the same file
            //of the rest of languages, normalizing the text and removing the
            //special characters and the xml tags.

            for (String language : folderList.keySet()) {
                File languageFile = new File(folderList.get(language).getAbsolutePath() + "/" + fileName);

                if (languageFile.exists()) {
                    String text = FileUtils.readFileToString(languageFile, Charset.forName("UTF-8"));
                    text = StringNormalize.stringNormalize(text);

                    actualFile.put(language, text);

                }

            }

        } catch (IOException ex) {
            System.err.println("Error: " + ex.toString());
        }

        //Then we search in the text of the reference language for words with the 
        //first caracter in uppercase.
        HashSet<String> posibleNames;

        posibleNames = getPosibleNames(actualFile.get(refLanguage));

        //System.out.println(posibleNames.toString());

        eliminateNames(posibleNames, actualFile);

        for (String lang : actualFile.keySet()) {
            try {
                //Copy the filter file in out folder
                FileUtils.writeStringToFile(new File(out.getAbsolutePath() + "/" + lang + "/" + fileName),
                        actualFile.get(lang), Charset.forName("UTF-8"));
            } catch (IOException ex) {
                System.err.println("Error: " + ex.toString());
            }
        }

    }
}

From source file:com.parse.ParseKeyValueCache.java

private static File getKeyValueCacheFile(String key) {
    final String suffix = '.' + key;
    File[] matches = getKeyValueCacheDir().listFiles(new FilenameFilter() {
        @Override/*from  w  w w.ja  v  a2  s .  com*/
        public boolean accept(File dir, String filename) {
            return filename.endsWith(suffix);
        }
    });
    return (matches == null || matches.length == 0) ? null : matches[0];
}

From source file:org.metasyntactic.utilities.ExceptionUtilities.java

private static String[] searchForStackTraces() {
    File dir = new File(FilesPath + "/");
    dir.mkdirs();/* w ww  .j a  va 2s  . c  o  m*/

    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");
        }
    };
    return dir.list(filter);
}

From source file:functionaltests.CopyFileExecutable.java

@Override
public Serializable execute(TaskResult... results) throws Throwable {
    File localSpaceFolder = new File(".");
    System.out.println("Using current space folder " + localSpaceFolder.getAbsolutePath());
    System.out.println(Arrays.toString(localSpaceFolder.listFiles()));
    File[] inputFiles = localSpaceFolder.listFiles(new FilenameFilter() {
        @Override//from www .ja  v  a  2s .c  o  m
        public boolean accept(File dir, String name) {
            return name.endsWith(TestSmartProxy.inputFileExt);
        }
    });

    for (File inputFile : inputFiles) {
        String outputFileName = inputFile.getName().replace("input", "output")
                .replace(TestSmartProxy.inputFileExt, TestSmartProxy.outputFileExt);
        File outputFile = new File(outputFileName);
        FileUtils.copyFile(inputFile, outputFile);
        System.out.println("Written file " + outputFile.getAbsolutePath());
    }
    return "OK";
}

From source file:com.fusesource.forge.jmstest.config.SpringConfigHelper.java

public void setSpringConfigLocations(List<String> locations) {
    springConfigLocations = new ArrayList<String>();

    for (String location : locations) {
        System.err.println("location -> " + location);
        File f = new File(location);
        if (f.exists()) {
            if (f.canRead()) {
                if (f.isDirectory()) {
                    for (String fileName : f.list(new FilenameFilter() {
                        public boolean accept(File dir, String name) {
                            File candidate = new File(dir, name);
                            if (!candidate.isFile()) {
                                return false;
                            } else {
                                return name.endsWith(".xml");
                            }//from  w w  w  .j  a va  2  s  .  co m
                        }
                    })) {
                        String absFileName = new File(f, fileName).getAbsolutePath();
                        log().info("Found xml file: " + absFileName);
                        springConfigLocations.add(absFileName);
                    }
                } else if (f.isFile()) {
                    if (location.endsWith(".xml")) {
                        String absFileName = f.getAbsolutePath();
                        log().info("Found xml file: " + absFileName);
                        springConfigLocations.add(absFileName);
                    }
                }
            }
        }
    }

    applicationContext = null;
}

From source file:com.jroossien.boxx.util.Utils.java

public static Map<String, File> getFiles(File dir, final String extension) {
    Map<String, File> names = new HashMap<String, File>();
    if (dir == null || !dir.exists() || !dir.isDirectory()) {
        return names;
    }/*  w  w w .  jav a2s.  com*/

    File[] files = dir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith("." + extension);
        }
    });

    for (File file : files) {
        names.put(file.getName().substring(0, file.getName().length() - extension.length() - 1), file);
    }

    return names;
}

From source file:com.pinterest.terrapin.tools.HFileGeneratorTest.java

@Test
public void testGenerateHFiles() throws IOException {
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    int numOfPart = 10;
    int numOfKeys = 1000;
    HFileGenerator.generateHFiles(fs, conf, outputDir, PartitionerType.CASCADING, numOfPart, numOfKeys);
    FilenameFilter hfileFilter = new FilenameFilter() {
        @Override//from  w w  w  . j a v  a  2 s  .com
        public boolean accept(File dir, String name) {
            return name.startsWith(Constants.FILE_PREFIX);
        }
    };
    File[] hfiles = outputDir.listFiles(hfileFilter);
    assertEquals(numOfPart, hfiles.length);

    int count = 0;
    for (File hfile : hfiles) {
        HColumnDescriptor columnDescriptor = new HColumnDescriptor();
        columnDescriptor.setBlockCacheEnabled(false);
        HFile.Reader reader = HFile.createReader(fs, new Path(hfile.toURI()),
                new CacheConfig(conf, columnDescriptor));
        count += reader.getEntries();
        reader.close();
    }
    assertEquals(numOfKeys, count);
}

From source file:eu.udig.style.advanced.common.StyleManager.java

/**
 * Reload the style folder content in the {@link TableViewer viewer}.
 *///from ww w  .j  a  v  a  2  s  .  c  o m
public void reloadStyleFolder() {
    File[] sldFilesArray = styleFolderFile.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(SLD_EXTENTION);
        }
    });

    List<StyleWrapper> newStylesList = new ArrayList<StyleWrapper>();
    for (File file : sldFilesArray) {
        try {
            StyledLayerDescriptor sld = readStyle(file);
            Style style = SLDs.getDefaultStyle(sld);
            String name = FilenameUtils.removeExtension(file.getName());
            style.setName(name);

            StyleWrapper styleWrapper = new StyleWrapper(style);
            newStylesList.add(styleWrapper);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    stylesViewer.setInput(newStylesList);
}

From source file:eu.sisob.uma.restserver.services.crawler.CrawlerTask.java

public static boolean relaunch(String user, String pass, String task_code, String code_task_folder,
        String email, StringWriter message) {
    boolean success = false;

    String results_data_folder = code_task_folder + File.separator + AuthorizationManager.results_dirname;
    File results_data_dir = new File(results_data_folder);

    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {

            if (name.endsWith(AuthorizationManager.results_dirname) && dir.isDirectory()) {
                return true;
            } else {
                return false;
            }/*  w w  w.java2s.  c om*/
        }
    };

    try {
        int results_dir = results_data_dir.getParentFile().list(filter).length;
        results_data_dir.renameTo(new File(results_dir + "." + results_data_dir.getName()));
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex.getMessage(), ex);
    }

    if (success) {
        success = CrawlerTask.launch(user, pass, task_code, code_task_folder, email, message);
    }

    return success;
}

From source file:com.bladecoder.engineeditor.model.Chapter.java

public String[] getChapters() {

    String[] chapters = new File(modelPath).list(new FilenameFilter() {
        @Override/*from ww  w .  j  a v  a2s.c  om*/
        public boolean accept(File arg0, String arg1) {
            if (!arg1.endsWith(EngineAssetManager.CHAPTER_EXT) && !arg1.endsWith(".chapter"))
                return false;

            return true;
        }
    });

    for (int i = 0; i < chapters.length; i++) {
        if (chapters[i].endsWith(EngineAssetManager.CHAPTER_EXT))
            chapters[i] = chapters[i].substring(0, chapters[i].lastIndexOf(EngineAssetManager.CHAPTER_EXT));
        else
            chapters[i] = chapters[i].substring(0, chapters[i].lastIndexOf(".chapter"));
    }

    return chapters;
}