List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:de.tudarmstadt.lt.lm.app.PerplexityClient.java
@Override public void run() { _lm_prvdr = AbstractStringProvider.connectToServer(_host, _rmiport, _id); if (_lm_prvdr == null) { LOG.error("Could not connect to language model at '{}'", _rmi_string); return;/*from ww w . j av a 2 s. co 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_all = new ModelPerplexity<>(_lm_prvdr); _perplexity_file = new ModelPerplexity<>(_lm_prvdr); _pout = System.out; if (!"-".equals(_out.trim())) { 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); _perplexity_file.reset(); 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); } 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.get(), _perplexity_all.get(), _max_ngram, _max_prob, _min_ngram, _min_prob, _num_ngrams, _oovreflm_oov_terms, _oovreflm_oov_ngrams); LOG.info(o); if (!_quiet) write(String.format("%s%n", o)); } } } 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-handling: %s \tOov-terms: %d \tOov-ngrams: %d \toov-reflm-handling: %s \tOov-reflm-terms: %d \tOov-reflm-ngrams: %d", _rmi_string, _file, _perplexity_all.get(), _max_ngram, _max_prob, _min_ngram, _min_prob, _num_ngrams, _no_oov ? "oov excluded" : "oov included", _oov_terms, _oov_ngrams, _no_oov_reflm ? "oov-reflm excluded" : "oov-reflm included", _oovreflm_oov_terms, _oovreflm_oov_ngrams); LOG.info(o); if (!_quiet) write(String.format("%s%n", o)); else write(String.format("%s\t%s\t%6.3e\t%d\t%s\t%d\t%d\t%s\t%d\t%d%n", _rmi_string, _file, _perplexity_all.get(), _num_ngrams, _no_oov ? "oov excluded" : "oov included", _oov_ngrams, _oov_terms, _no_oov_reflm ? "oov-reflm excluded" : "oov-reflm included", _oovreflm_oov_ngrams, _oovreflm_oov_terms)); }
From source file:com.haru.ui.image.workers.MediaProcessorThread.java
protected void manageDiretoryCache(final int maxDirectorySize, final int maxThresholdDays, final String extension) { File directory = null;// w w w. j ava 2 s . c o m directory = new File(foldername); File[] files = directory.listFiles(); long count = 0; if (files == null) { return; } for (File file : files) { count = count + file.length(); } if (/* TODO: DEBUG */ true) { Log.i(TAG, "Directory size: " + count); } if (count > maxDirectorySize) { final long today = Calendar.getInstance().getTimeInMillis(); FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (today - pathname.lastModified() > maxThresholdDays && pathname.getAbsolutePath() .toUpperCase(Locale.ENGLISH).endsWith(extension.toUpperCase(Locale.ENGLISH))) { return true; } else { return false; } } }; File[] filterFiles = directory.listFiles(filter); for (File file : filterFiles) { file.delete(); } } }
From source file:com.liferay.util.FileUtil.java
public static File[] listFileHandles(File dir, Boolean includeSubDirs) throws IOException { FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); }/*from w ww. j ava 2s . c o m*/ }; File[] subFolders = dir.listFiles(fileFilter); List<File> files = new ArrayList<File>(); List<File> fileArray = new ArrayList<File>( FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, includeSubDirs ? TrueFileFilter.INSTANCE : null)); for (File file : fileArray) { if (file.isFile()) { if (includeSubDirs && containsParentFolder(file, subFolders)) { files.add(file); } else { files.add(file); } } } return (File[]) files.toArray(new File[0]); }
From source file:com.cars.manager.utils.imageChooser.threads.MediaProcessorThread.java
protected void manageDiretoryCache(final int maxDirectorySize, final int maxThresholdDays, final String extension) { File directory = null;// www. j a va 2 s.co m directory = new File(FileUtils.getDirectory(foldername)); File[] files = directory.listFiles(); long count = 0; if (files == null) { return; } for (File file : files) { count = count + file.length(); } if (Config.DEBUG) { Log.i(TAG, "Directory size: " + count); } if (count > maxDirectorySize) { final long today = Calendar.getInstance().getTimeInMillis(); FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (today - pathname.lastModified() > maxThresholdDays && pathname.getAbsolutePath() .toUpperCase(Locale.ENGLISH).endsWith(extension.toUpperCase(Locale.ENGLISH))) { return true; } else { return false; } } }; File[] filterFiles = directory.listFiles(filter); for (File file : filterFiles) { file.delete(); } } }
From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java
private static File getPreviewFile(TranscodeRequest request, ServletConfig config) { final String uuid = request.getPid(); final FileFilter filter = new FileFilter() { @Override/*from w w w . ja v a2 s . c o m*/ public boolean accept(File pathname) { return pathname.getName().startsWith(uuid + ".") && pathname.getName().contains("preview"); } }; File outputDir = getOutputDir(request, config); return outputDir.listFiles(filter)[0]; }
From source file:org.apache.carbondata.sdk.file.AvroCarbonWriterTest.java
@Test public void testWriteNestedRecordWithMeasure() throws IOException { FileUtils.deleteDirectory(new File(path)); 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 {/*w w w. j a v a 2s .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:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java
private static boolean hasExtractedBroadcast(TranscodeRequest request, ServletConfig config) { final String uuid = request.getPid(); final FileFilter filter = new FileFilter() { @Override/*from w w w .j a v a2s .co m*/ public boolean accept(File pathname) { return pathname.getName().startsWith(uuid + ".") && !pathname.getName().contains("preview"); } }; File outputDir = getOutputDir(request, config); return outputDir.listFiles(filter).length > 0; }
From source file:interactivespaces.workbench.tasks.WorkbenchTaskContext.java
/** * Add all JAR files from the given directory to the list of files. * * @param directory/* ww w. ja v a 2 s.co m*/ * the directory to get the jar files from * @param fileList * the list to add the files to */ public void addJarFiles(File directory, List<File> fileList) { File[] files = directory.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(FILENAME_JAR_EXTENSION); } }); if (files != null) { Collections.addAll(fileList, files); } }
From source file:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java
protected void manageDiretoryCache(final String extension) { if (!clearOldFiles) { return;/*from w ww . j a v a 2 s .c om*/ } File directory = null; directory = new File(FileUtils.getDirectory(foldername)); File[] files = directory.listFiles(); long count = 0; if (files == null) { return; } for (File file : files) { count = count + file.length(); } if (BuildConfig.DEBUG) { Log.i(TAG, "Directory size: " + count); } if (count > MAX_DIRECTORY_SIZE) { final long today = Calendar.getInstance().getTimeInMillis(); FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (today - pathname.lastModified() > MAX_THRESHOLD_DAYS && pathname.getAbsolutePath() .toUpperCase(Locale.ENGLISH).endsWith(extension.toUpperCase(Locale.ENGLISH))) { return true; } else { return false; } } }; File[] filterFiles = directory.listFiles(filter); int deletedFileCount = 0; for (File file : filterFiles) { deletedFileCount++; file.delete(); } Log.i(TAG, "Deleted " + deletedFileCount + " files"); } }
From source file:com.liferay.util.FileUtil.java
public static String[] listFiles(File dir, Boolean includeSubDirs) throws IOException { FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); }//from ww w .j a va 2 s.c o m }; File[] subFolders = dir.listFiles(fileFilter); List<String> files = new ArrayList<String>(); List<File> fileArray = new ArrayList<File>( FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, includeSubDirs ? TrueFileFilter.INSTANCE : null)); for (File file : fileArray) { if (file.isFile()) { if (includeSubDirs && containsParentFolder(file, subFolders)) { files.add(file.getParentFile().getName() + File.separator + file.getName()); } else { files.add(file.getName()); } } } return (String[]) files.toArray(new String[0]); }