List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:org.apache.carbondata.sdk.file.CSVCarbonWriterTest.java
@Test public void testAllPrimitiveDataType() throws IOException { String path = "./testWriteFiles"; FileUtils.deleteDirectory(new File(path)); Field[] fields = new Field[9]; fields[0] = new Field("stringField", DataTypes.STRING); fields[1] = new Field("intField", DataTypes.INT); fields[2] = new Field("shortField", DataTypes.SHORT); fields[3] = new Field("longField", DataTypes.LONG); fields[4] = new Field("doubleField", DataTypes.DOUBLE); fields[5] = new Field("boolField", DataTypes.BOOLEAN); fields[6] = new Field("dateField", DataTypes.DATE); fields[7] = new Field("timeField", DataTypes.TIMESTAMP); fields[8] = new Field("decimalField", DataTypes.createDecimalType(8, 2)); try {// ww w . j av a 2s . c om CarbonWriterBuilder builder = CarbonWriter.builder().outputPath(path); CarbonWriter writer = builder.withCsvInput(new Schema(fields)).writtenBy("CSVCarbonWriterTest").build(); for (int i = 0; i < 100; i++) { Object[] row = new Object[] { "robot" + (i % 10), i, i, (Long.MAX_VALUE - i), ((double) i / 2), true, "2019-03-02", "2019-02-12 03:03:34", "1.234567" }; writer.write(row); } 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.assertTrue(dataFiles.length > 0); FileUtils.deleteDirectory(new File(path)); }
From source file:atg.tools.dynunit.test.AtgDustCase.java
/** * Every *.properties file copied using this method will have it's scope (if one is available) set to global. * * @param sourceDirectories//from w w w. j av a 2s .com * One or more directories containing needed configuration files. * @param destinationDirectory * where to copy the above files to. This will also be the * configuration location. * @param excludedDirectories * One or more directories not to include during the copy * process. Use this one to speeds up the test cycle * considerably. You can also call it with an empty * {@link String[]} or <code>null</code> if nothing should be * excluded * * @throws IOException * Whenever some file related error's occur. */ protected final void copyConfigurationFiles(@NotNull final String[] sourceDirectories, @NotNull final String destinationDirectory, @Nullable final String... excludedDirectories) throws IOException { logger.entry(sourceDirectories, destinationDirectory, excludedDirectories); setConfigurationLocation(destinationDirectory); logger.info("Copying configurating files and forcing global scope on all configs."); preCopyingOfConfigurationFiles(sourceDirectories, excludedDirectories); for (final String sourceDirectory : sourceDirectories) { FileUtils.copyDirectory(new File(sourceDirectory), new File(destinationDirectory), new FileFilter() { @Override public boolean accept(final File file) { return ArrayUtils.contains(excludedDirectories, file.getName()); } }); } forceGlobalScopeOnAllConfigs(destinationDirectory); if (FileUtil.isDirty()) { FileUtil.serialize(GLOBAL_FORCE_SER, FileUtil.getConfigFilesTimestamps()); } logger.exit(); }
From source file:nl.cad.tpsparse.Main.java
/** * @param folder the folder to scan./* w ww. j a v a 2 s . c o m*/ * @return the tps files in the folder. */ private static File[] listFiles(File folder) { return folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".tps"); } }); }
From source file:de.tudarmstadt.lt.lm.app.LineProbPerp.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;/*from w w w . ja v a 2 s .c om*/ } _perp = new ModelPerplexity<>(_lm_prvdr); _perp_oov = 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:de.tudarmstadt.ukp.dkpro.core.decompounding.web1t.LuceneIndexer.java
/** * Create the index. This is a very long running function. It will output some information on * stdout./*ww w .ja va 2 s. co m*/ */ public void index() throws FileNotFoundException, InterruptedException { List<File> files; if (web1tFolder.isFile()) { files = Arrays.asList(new File[] { web1tFolder }); } else if (web1tFolder.isDirectory()) { files = Arrays.asList(web1tFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".txt"); } })); } else { throw new FileNotFoundException("File " + web1tFolder + " cannot be found."); } if (indexes > files.size()) { indexes = files.size(); } logger.info("Oh, you started a long running task. Take a cup of coffee ..."); int perIndex = (int) Math.ceil((float) files.size() / (float) indexes); Worker[] workers = new Worker[indexes]; for (int i = 0; i < indexes; i++) { int start = i * perIndex; int end = start + perIndex; if (end > files.size()) { end = files.size(); } logger.info(StringUtils.join(files.subList(start, end), ", ")); Worker w = new Worker(files.subList(start, end), new File(outputPath.getAbsoluteFile() + "/" + i), dictionary); w.start(); workers[i] = w; } for (int i = 0; i < indexes; i++) { workers[i].join(); } logger.info("Great, index is ready. Have fun!"); }
From source file:com.impetus.ankush.common.utils.UploadHandler.java
/** * Gets the available file list.//from w w w .j a v a2 s . c om * * @param parameters * the parameters * @return The List of file names for the found files inside the Category * folder. */ public Map getAvailableFileList(Map<String, String> parameters) { Map result = new HashMap<String, Object>(); /* Getting the Category value from the Parameters map */ String category = parameters.get("category"); /* Getting the Pattern value from the Parameters map */ final String pattern = parameters.get("pattern"); /* Getting the Path of folder for the category */ String folderPath = (String) AppStore.getObject(category.toLowerCase()); List<String> fileList = new ArrayList<String>(); if (folderPath != null) { result.put("path", folderPath); File repoDirs = new File(folderPath); FileFilter fileFilter = new FileFilter() { @Override public boolean accept(File file) { String regex = pattern; if (regex == null) { return true; } else if (regex.startsWith("*")) { return false; } return file.getName().matches(regex); } }; for (File file : repoDirs.listFiles(fileFilter)) { fileList.add(file.getName()); } result.put("files", fileList); } return result; }
From source file:cc.pp.analyzer.paoding.analyzer.impl.CompiledFileDictionaries.java
@Override public synchronized void startDetecting(int interval, DifferenceListener l) { if (detector != null || interval < 0) { return;/*w w w .ja v a2 s .c o m*/ } Detector detector = new Detector(); detector.setHome(dicHome); detector.setFilter(null); detector.setFilter(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getPath().endsWith(".dic.compiled") || pathname.getPath().endsWith(".metadata"); } }); detector.setLastSnapshot(detector.flash()); detector.setListener(l); detector.setInterval(interval); detector.start(true); this.detector = detector; }
From source file:ddf.security.pdp.xacml.processor.PollingPolicyFinderModule.java
private FileFilter getXmlFileFilter() { FileFilter xmlFileFilter = new FileFilter() { public boolean accept(File pathName) { return pathName.getName().toLowerCase().endsWith(".xml"); }//from ww w .j av a2s.c om }; return xmlFileFilter; }
From source file:org.apache.carbondata.sdk.file.CSVNonTransactionalCarbonWriterTest.java
@Test public void testAllPrimitiveDataType() throws IOException { // TODO: write all data type and read by CarbonRecordReader to verify the content String path = "./testWriteFiles"; FileUtils.deleteDirectory(new File(path)); Field[] fields = new Field[9]; fields[0] = new Field("stringField", DataTypes.STRING); fields[1] = new Field("intField", DataTypes.INT); fields[2] = new Field("shortField", DataTypes.SHORT); fields[3] = new Field("longField", DataTypes.LONG); fields[4] = new Field("doubleField", DataTypes.DOUBLE); fields[5] = new Field("boolField", DataTypes.BOOLEAN); fields[6] = new Field("dateField", DataTypes.DATE); fields[7] = new Field("timeField", DataTypes.TIMESTAMP); fields[8] = new Field("decimalField", DataTypes.createDecimalType(8, 2)); try {/* w ww . j a v a 2 s . com*/ CarbonWriterBuilder builder = CarbonWriter.builder().uniqueIdentifier(System.currentTimeMillis()) .isTransactionalTable(false).taskNo(System.nanoTime()).outputPath(path); CarbonWriter writer = builder.buildWriterForCSVInput(new Schema(fields)); for (int i = 0; i < 100; i++) { String[] row = new String[] { "robot" + (i % 10), String.valueOf(i), String.valueOf(i), String.valueOf(Long.MAX_VALUE - i), String.valueOf((double) i / 2), String.valueOf(true), "2019-03-02", "2019-02-12 03:03:34" }; writer.write(row); } writer.close(); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } File segmentFolder = new File(path); Assert.assertTrue(segmentFolder.exists()); File[] dataFiles = segmentFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT); } }); Assert.assertNotNull(dataFiles); Assert.assertTrue(dataFiles.length > 0); FileUtils.deleteDirectory(new File(path)); }
From source file:org.ocelotds.integration.AbstractOcelotTest.java
/** * Add srv_xxxx.js and srv_xxxx.ServiceProvider.class * * @param root// ww w . j a v a 2s .c om * @param resourceContainer * @param classContainer */ public static void addJSAndProvider(final String root, ResourceContainer resourceContainer, ClassContainer classContainer) { File classes = new File(root); File[] jsFiles = classes.listFiles(new FileFilter() { @Override public boolean accept(File file) { String name = file.getName(); return file.isFile() && name.startsWith("srv_") && name.endsWith(".js"); } }); for (File file : jsFiles) { String jsName = file.getName(); String providerPackage = jsName.replaceAll(".js$", ""); classContainer.addPackage(providerPackage); resourceContainer.addAsResource(new FileAsset(file), file.getName()); } }