List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl.java
private boolean containsSiteFile(File f) { if (!f.isDirectory()) { return false; } else {//from w ww. java 2 s . c o m File[] files = f.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith("site.xml"); } }); return files != null && files.length > 0; } }
From source file:com.runwaysdk.dataaccess.io.Backup.java
@SuppressWarnings("unused") private void backupCacheFile() { this.logPrintStream .println(ServerExceptionMessageLocalizer.backingUpCacheMessage(Session.getCurrentLocale())); try {/*from w w w . ja v a2s.co m*/ // Make the temp cache directory File directory = new File(this.tempBackupFileLocation + File.separator + CACHE + File.separator); String copyTo = directory.getAbsolutePath(); directory.mkdirs(); File cacheDir = new File(this.cacheDir); this.log.trace("Backing up cache files from [" + cacheDir + "] to [" + copyTo + "]."); FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return file.getName().startsWith(Backup.this.cacheName); } }; File[] files = cacheDir.listFiles(filter); if (files != null) { for (File file : files) { this.log.debug("Backing up cache file [" + file + "]."); FileInputStream iStream = new FileInputStream(file); FileOutputStream oStream = new FileOutputStream( new File(copyTo + File.separator + file.getName())); FileIO.write(oStream, iStream); } } } catch (IOException e) { CreateBackupException cbe = new CreateBackupException(e); cbe.setLocation(new File(this.tempBackupFileLocation + File.separator + CACHE + File.separator) .getAbsolutePath()); throw cbe; } this.log.trace("Finished backing up the cache files."); }
From source file:org.apache.carbondata.sdk.file.AvroCarbonWriterTest.java
@Test public void testWriteNestedRecord() throws IOException { FileUtils.deleteDirectory(new File(path)); String newAvroSchema = "{" + " \"type\" : \"record\", " + " \"name\" : \"userInfo\", " + " \"namespace\" : \"my.example\", " + " \"fields\" : [{\"name\" : \"username\", " + " \"type\" : \"string\", " + " \"default\" : \"NONE\"}, " + " {\"name\" : \"age\", " + " \"type\" : \"int\", " + " \"default\" : -1}, " + "{\"name\" : \"address\", " + " \"type\" : { " + " \"type\" : \"record\", " + " \"name\" : \"mailing_address\", " + " \"fields\" : [ {" + " \"name\" : \"street\", " + " \"type\" : \"string\", " + " \"default\" : \"NONE\"}, { " + " \"name\" : \"city\", " + " \"type\" : \"string\", " + " \"default\" : \"NONE\"}, " + " ]}, " + " \"default\" : {} " + " } " + "}"; String mySchema = "{" + " \"name\": \"address\", " + " \"type\": \"record\", " + " \"fields\": [ " + " { \"name\": \"name\", \"type\": \"string\"}, " + " { \"name\": \"age\", \"type\": \"int\"}, " + " { " + " \"name\": \"address\", " + " \"type\": { " + " \"type\" : \"record\", " + " \"name\" : \"my_address\", " + " \"fields\" : [ " + " {\"name\": \"street\", \"type\": \"string\"}, " + " {\"name\": \"city\", \"type\": \"string\"} " + " ]} " + " } " + "] " + "}"; String json = "{\"name\":\"bob\", \"age\":10, \"address\" : {\"street\":\"abc\", \"city\":\"bang\"}}"; // conversion to GenericData.Record Schema nn = new Schema.Parser().parse(mySchema); GenericData.Record record = TestUtil.jsonToAvro(json, mySchema); try {/*from w w w. ja v a 2 s . c o m*/ CarbonWriter writer = CarbonWriter.builder().outputPath(path).withAvroInput(nn) .writtenBy("AvroCarbonWriterTest").build(); for (int i = 0; i < 100; i++) { writer.write(record); } writer.close(); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } File[] dataFiles = new File(path).listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT); } }); Assert.assertNotNull(dataFiles); Assert.assertEquals(1, dataFiles.length); FileUtils.deleteDirectory(new File(path)); }
From source file:de.tudarmstadt.lt.lm.app.SentPerp.java
@Override public void run() { _lm_prvdr = AbstractStringProvider.connectToServer(_host, _rmiport, _name); if (_lm_prvdr == null) { LOG.error("Could not connect to language model at '{}'", _rmi_string); return;//www.ja v a2 s.c om } if (_oovreflm_name != null) { _lm_prvdr_oovref = AbstractStringProvider.connectToServer(_host, _rmiport, _oovreflm_name); if (_lm_prvdr_oovref == null) { LOG.error("Could not connect to language model at '{}'", _oovreflm_name); return; } } else _lm_prvdr_oovref = _lm_prvdr; _pout = System.out; if (!"-".equals(_out)) { try { _pout = new PrintStream(new FileOutputStream(new File(_out), true)); } catch (FileNotFoundException e) { LOG.error("Could not open ouput file '{}' for writing.", _out, e); System.exit(1); } } if ("-".equals(_file.trim())) { LOG.info("{}: Processing text from stdin ('{}').", _rmi_string, _file); try { run(new InputStreamReader(System.in, "UTF-8")); } catch (Exception e) { LOG.error("{}: Could not compute perplexity from file '{}'.", _rmi_string, _file, e); } } else { File f_or_d = new File(_file); if (!f_or_d.exists()) throw new Error(String.format("%s: File or directory '%s' not found.", _rmi_string, _file)); if (f_or_d.isFile()) { LOG.info("{}: Processing file '{}'.", _rmi_string, f_or_d.getAbsolutePath()); try { run(new InputStreamReader(new FileInputStream(f_or_d), "UTF-8")); } catch (Exception e) { LOG.error("{}: Could not compute perplexity from file '{}'.", _rmi_string, f_or_d.getAbsolutePath(), e); } } if (f_or_d.isDirectory()) { File[] txt_files = f_or_d.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith(".txt"); } }); for (int i = 0; i < txt_files.length; i++) { File f = txt_files[i]; LOG.info("{}: Processing file '{}' ({}/{}).", _rmi_string, f.getAbsolutePath(), i + 1, txt_files.length); try { run(new InputStreamReader(new FileInputStream(f), "UTF-8")); } catch (Exception e) { LOG.error("{}: Could not compute perplexity from file '{}'.", _rmi_string, f.getAbsolutePath(), e); } double entropy = -_sum_log10_prob_sents / _num_sents; _perplexity_all = Math.pow(10, entropy); String o = String.format( "%s: (intermediate results) \t %s \tPerplexity (file): %6.3e \tPerplexity (cum): %6.3e \tMax: log_10(p(%s))=%6.3e \tMin: log_10(p(%s))=%6.3e \tngrams (cum): %d \tOov-terms (cum): %d \tOov-ngrams (cum): %d", _rmi_string, f.getAbsoluteFile(), _perplexity_file, _perplexity_all, _max_ngram, _max_prob, _min_ngram, _min_prob, _num_ngrams, _oov_terms, _oov_ngrams); LOG.info(o); if (!_quiet) write(String.format("%s%n", o)); } } } double entropy = -_sum_log10_prob_sents / _num_sents; _perplexity_all = Math.pow(10, entropy); String o = String.format( "%s\t%s\tPerplexity: %6.3e \tMax: log_10(p(%s))=%6.3e \tMin: log_10(p(%s))=%6.3e \tngrams: %d \tOov-terms: %d \tOov-ngrams: %d", _rmi_string, _file, _perplexity_all, _max_ngram, _max_prob, _min_ngram, _min_prob, _num_ngrams, _oov_terms, _oov_ngrams); LOG.info(o); if (!_quiet) write(String.format("%s%n", o)); else write(String.format("%s\t%s\t%6.3e%n", _rmi_string, _file, _perplexity_all)); }
From source file:de.tudarmstadt.lt.lm.app.PerpDoc.java
@Override public void run() { _lm_prvdr = AbstractStringProvider.connectToServer(_host, _rmiport, _name); if (_lm_prvdr == null) { LOG.error("Could not connect to language model at '{}'", _rmi_string); return;// www . j a v a 2 s . c o m } if (_oovreflm_name != null) { _lm_prvdr_oovref = AbstractStringProvider.connectToServer(_host, _rmiport, _oovreflm_name); if (_lm_prvdr_oovref == null) { LOG.error("Could not connect to language model at '{}'", _oovreflm_name); return; } } else _lm_prvdr_oovref = _lm_prvdr; _perplexity_doc = new ModelPerplexity<>(_lm_prvdr); _pout = System.out; if (!"-".equals(_out)) { try { _pout = new PrintStream(new FileOutputStream(new File(_out), true)); } catch (FileNotFoundException e) { LOG.error("Could not open ouput file '{}' for writing.", _out, e); System.exit(1); } } if ("-".equals(_file.trim())) { LOG.info("{}: Processing text from stdin ('{}').", _rmi_string, _file); try { run(new InputStreamReader(System.in, "UTF-8")); } catch (Exception e) { LOG.error("{}: Could not compute perplexity from file '{}'.", _rmi_string, _file, e); } } else { File f_or_d = new File(_file); if (!f_or_d.exists()) throw new Error(String.format("%s: File or directory '%s' not found.", _rmi_string, _file)); if (f_or_d.isFile()) { LOG.info("{}: Processing file '{}'.", _rmi_string, f_or_d.getAbsolutePath()); try { run(new InputStreamReader(new FileInputStream(f_or_d), "UTF-8")); } catch (Exception e) { LOG.error("{}: Could not compute perplexity from file '{}'.", _rmi_string, f_or_d.getAbsolutePath(), e); } } if (f_or_d.isDirectory()) { File[] txt_files = f_or_d.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith(".txt"); } }); for (int i = 0; i < txt_files.length; i++) { File f = txt_files[i]; LOG.info("{}: Processing file '{}' ({}/{}).", _rmi_string, f.getAbsolutePath(), i + 1, txt_files.length); try { run(new InputStreamReader(new FileInputStream(f), "UTF-8")); } catch (Exception e) { LOG.error("{}: Could not compute perplexity from file '{}'.", _rmi_string, f.getAbsolutePath(), e); } } } } }
From source file:au.org.ala.biocache.util.ParamsCache.java
/** * delete save params cache objects that are older than MAX_FILE_AGE. * *//*from w w w.j a va 2s. c o m*/ static public void deleteOldParamFiles() { try { File dir = new File(TEMP_FILE_PATH); FileFilter ff = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.getName().startsWith(FILE_PREFIX)) { try { long l = Long .parseLong(pathname.getName().replace(FILE_PREFIX, "").replace(".json", "")); if ((System.currentTimeMillis() - l) > MAX_FILE_AGE) { return true; } } catch (Exception e) { } } return false; } }; File[] filesToRemove = dir.listFiles(ff); for (File f : filesToRemove) { FileUtils.deleteQuietly(f); logger.info("removing cached query file: " + f.getName()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:de.escidoc.core.admin.business.DataBaseMigrationTool.java
/** * Get an ordered list of all available updates found in the given * directory./* ww w. jav a2 s . c om*/ * * @param dirName * directory which contains sub directories with the SQL scripts * * @return ordered list of all available updates */ private Collection<Version> getUpdates(final String dirName) { Collection<Version> result = new TreeSet<Version>(); File dir = new File(dirName); File[] updates = dir.listFiles(new FileFilter() { public boolean accept(final File pathname) { return (pathname != null) && (pathname.isDirectory()); } }); if (updates != null) { for (File update : updates) { if (!update.getName().startsWith(".")) { result.add(new Version(update.getName())); } } } return result; }
From source file:adalid.commons.util.FilUtils.java
public static FileFilter visibleDirectoryFilter() { return new FileFilter() { @Override/*w w w . ja va2s.c om*/ public boolean accept(File file) { return isVisibleDirectory(file); } }; }
From source file:de.blizzy.documentr.access.UserStore.java
private List<String> listUsers(ILockedRepository repo) { File workingDir = RepositoryUtil.getWorkingDir(repo.r()); FileFilter filter = new FileFilter() { @Override/*w w w .ja va 2 s . c o m*/ public boolean accept(File file) { return file.isFile() && file.getName().endsWith(USER_SUFFIX); } }; List<File> files = Lists.newArrayList(workingDir.listFiles(filter)); Function<File, String> function = new Function<File, String>() { @Override public String apply(File file) { return StringUtils.substringBeforeLast(file.getName(), USER_SUFFIX); } }; List<String> users = Lists.newArrayList(Lists.transform(files, function)); Collections.sort(users); return users; }
From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java
private static File getBroadcastFile(TranscodeRequest request, ServletConfig config) { final String uuid = request.getPid(); final FileFilter filter = new FileFilter() { @Override/*from w w w . j a va 2 s .c o m*/ public boolean accept(File pathname) { return pathname.getName().startsWith(uuid + ".") && !pathname.getName().contains("preview"); } }; File outputDir = getOutputDir(request, config); log.trace("Looking for output in directory '" + outputDir + "'"); return outputDir.listFiles(filter)[0]; }