List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:de.tudarmstadt.ukp.csniper.webapp.evaluation.CorpusServiceImpl.java
private List<File> getCorporaDirs() { File[] dirs = repositoryPath.listFiles(new FileFilter() { @Override/*from w ww .j a va 2 s. c om*/ public boolean accept(File aPath) { return new File(aPath, corpusInfoFile).exists(); } }); return (dirs == null) ? new ArrayList<File>() : Arrays.asList(dirs); }
From source file:org.apache.carbondata.sdk.file.AvroCarbonWriterTest.java
@Test public void testWriteBasic() throws IOException { FileUtils.deleteDirectory(new File(path)); // Avro schema String avroSchema = "{" + " \"type\" : \"record\"," + " \"name\" : \"Acme\"," + " \"fields\" : [" + "{ \"name\" : \"name\", \"type\" : \"string\" }," + "{ \"name\" : \"age\", \"type\" : \"int\" }]" + "}"; String json = "{\"name\":\"bob\", \"age\":10}"; // conversion to GenericData.Record GenericData.Record record = TestUtil.jsonToAvro(json, avroSchema); try {/*from w w w .j a v a 2 s .c o m*/ CarbonWriter writer = CarbonWriter.builder().outputPath(path) .withAvroInput(new Schema.Parser().parse(avroSchema)).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:com.aliyun.odps.local.common.utils.LocalRunUtils.java
/** * ?????//from w w w .j a v a 2 s. c om */ public static List<File> listEmptyDirectory(File dir) { List<File> dataFiles = new ArrayList<File>(); File[] subDirs = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !pathname.isHidden(); } }); for (File file : subDirs) { if (file.isDirectory()) { listEmptyDirectory(file, dataFiles); } } return dataFiles; }
From source file:org.jspringbot.keyword.db.DbHelper.java
public void init() { ResourceEditor editor = new ResourceEditor(); editor.setAsText("classpath:db-queries/"); Resource dbDirResource = (Resource) editor.getValue(); boolean hasDBDirectory = true; boolean hasDBProperties = true; if (dbDirResource != null) { try {/* ww w . j av a 2s.c o m*/ File configDir = dbDirResource.getFile(); if (configDir.isDirectory()) { File[] propertiesFiles = configDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return StringUtils.endsWith(file.getName(), ".properties") || StringUtils.endsWith(file.getName(), ".xml"); } }); for (File propFile : propertiesFiles) { addExternalQueries(propFile); } } } catch (IOException ignore) { hasDBDirectory = false; } } editor.setAsText("classpath:db-queries.properties"); Resource dbPropertiesResource = (Resource) editor.getValue(); if (dbPropertiesResource != null) { try { if (dbPropertiesResource.getFile().isFile()) { addExternalQueries(dbPropertiesResource.getFile()); } } catch (IOException e) { hasDBProperties = false; } } editor.setAsText("classpath:db-queries.xml"); Resource dbXMLResource = (Resource) editor.getValue(); if (dbXMLResource != null && !hasDBProperties) { try { if (dbXMLResource.getFile().isFile()) { addExternalQueries(dbXMLResource.getFile()); } } catch (IOException e) { hasDBProperties = false; } } if (!hasDBDirectory && !hasDBProperties) { LOGGER.warn("No query sources found."); } begin(); }
From source file:de.unikassel.puma.openaccess.classification.PublicationClassificator.java
private void initialise() { ArrayList<ClassificationSource> cceList = new ArrayList<ClassificationSource>(); cceList.add(new ClassificationXMLChainElement(new JELClassification())); cceList.add(new ClassificationXMLChainElement(new ACMClassification())); cceList.add(new ClassificationTextChainElement(new DDCClassification())); File path = new File(xmlPath); if (path.isDirectory()) { File[] files = path.listFiles(new FileFilter() { @Override/*from w ww.j a va 2s . co m*/ public boolean accept(File file) { if (file.isDirectory()) { return false; } if (!file.toString().endsWith(".properties")) { return true; } return false; } }); for (File f : files) { try { Classification c = null; for (int i = 0; i < cceList.size() && !present(c); ++i) { c = cceList.get(i).getClassification(f.toURI().toURL()); } if (!present(c)) { log.error("Unable to parse " + f.getName()); continue; } log.info("Found Classification " + c.getClassName()); //try to read values from .properties file try { Properties properties = new Properties(); org.bibsonomy.model.Classification classification = new org.bibsonomy.model.Classification(); properties.load( new FileReader(f.getAbsolutePath().substring(0, f.getAbsolutePath().length() - 4) + ".properties")); classification.setName(properties.getProperty("name")); classification.setDesc(properties.getProperty("desc")); classification.setUrl(properties.getProperty("url")); classifications.put(classification, c); } catch (IOException e) { //no .properties file found, use the file name org.bibsonomy.model.Classification classification = new org.bibsonomy.model.Classification(); classification.setName(f.getName().substring(0, f.getName().length() - 4)); classifications.put(classification, c); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.liusoft.dlog4j.MailTransportQueue.java
/** * ??/*ww w .j a v a 2 s. c om*/ * @param mails ?,? * @param ident ?, * @param max_count * @return * @throws IOException */ public int read(Session ssn, List mails, List ident, int max_count) throws IOException { File fs = new File(path); File[] mailfiles = fs.listFiles(new FileFilter() { public boolean accept(File f) { if (f.length() > 0 && f.getName().endsWith(EML)) return true; return false; } }); if (mails != null) { for (int i = 0; i < mailfiles.length && i < max_count; i++) { FileInputStream fis = null; try { fis = new FileInputStream(mailfiles[i]); mails.add(new MimeMessage(ssn, fis)); if (ident != null) ident.add(mailfiles[i].getPath()); fis.close(); fis = null; mailfiles[i].delete(); } catch (MessagingException e) { String newfile = mailfiles[i].getPath() + ERR; mailfiles[i].renameTo(new File(newfile)); log.error("mail cache file destroy, rename to " + newfile, e); } catch (IOException e) { String newfile = mailfiles[i].getPath() + ERR; mailfiles[i].renameTo(new File(newfile)); log.error("IO Exception when read mail cache , rename to " + newfile, e); } finally { if (fis != null) fis.close(); } } } return mailfiles.length; }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooser.java
public void init() { if (_main == null || _Intent == null || _chooserView == null || _blnInitialized) { return;/* ww w . j a v a 2s .c o m*/ } try { Bundle extras = _Intent.getExtras(); if (extras != null) { unicode = extras.getBoolean("blnUniCode", true); DefaultDir = extras.getString("DefaultDir"); if (extras.getStringArrayList("filterFileExtension") != null) { extensions = extras.getStringArrayList("filterFileExtension"); fileFilter = new FileFilter() { @Override public boolean accept(File pathname) { return ((pathname.isDirectory()) || ExtensionsMatch(pathname)); } }; } } setCurrentDir((DefaultDir)); _blnInitialized = true; } catch (Exception ex) { Toast.makeText(_main, _main.getString(R.string.Error) + ex.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:jade.core.messaging.FileMessageStorage.java
public synchronized void loadAll(LoadListener ll) throws IOException { // Notify the listener that the load process started ll.loadStarted(""); // Scan all its valid subdirectories. File[] subdirs = baseDir.listFiles(new FileFilter() { public boolean accept(File f) { return f.isDirectory() && f.getName().startsWith(RECEIVER_PREFIX); }/*from w ww.j a v a 2 s .c o m*/ }); for (int i = 0; i < subdirs.length; i++) { File subdir = subdirs[i]; // Scan all its valid files. File[] files = subdir.listFiles(new FileFilter() { public boolean accept(File f) { return !f.isDirectory() && f.getName().startsWith(MESSAGE_PREFIX); } }); for (int j = 0; j < files.length; j++) { File toRead = files[j]; // Read the file content BufferedReader in = new BufferedReader(new FileReader(toRead)); // Read the number of copies String strHowMany = in.readLine(); long howMany = 1; try { howMany = Long.parseLong(strHowMany); } catch (NumberFormatException nfe) { // Do nothing; the default value will be used } try { // NL (23/01/04) GenericMessage are now stored using Java serialization String encodedMsg = in.readLine(); // String.getBytes is, in general, an irreversible operation. However, in this case, because // the content was previously encoded Base64, we can expect that we will have only valid Base64 chars. ByteArrayInputStream istream = new ByteArrayInputStream( Base64.decodeBase64(encodedMsg.getBytes("US-ASCII"))); ObjectInputStream p = new ObjectInputStream(istream); GenericMessage message = (GenericMessage) p.readObject(); istream.close(); // Use an ACL codec to read in the receiver AID StringACLCodec codec = new StringACLCodec(in, null); // Read the receiver AID AID receiver = codec.decodeAID(); // Notify the listener that a new item was loaded for (int k = 0; k < howMany; k++) { ll.itemLoaded(toRead.getName(), message, receiver); } } catch (ACLCodec.CodecException ce) { System.err.println("Error reading file " + toRead.getName() + " [" + ce.getMessage() + "]"); } catch (ClassNotFoundException cnfe) { System.err.println("Error reading file " + toRead.getName() + " [" + cnfe.getMessage() + "]"); } finally { in.close(); } } } // Notify the listener that the load process ended ll.loadEnded(""); }
From source file:com.googlecode.t7mp.steps.ResolveTomcatStep.java
private void copyToTomcatDirectory(final File unpackDirectory) throws IOException { File[] files = unpackDirectory.listFiles(new FileFilter() { @Override//ww w . j a va 2s . c om public boolean accept(final File file) { return file.isDirectory(); } }); // should only be one FileUtils.copyDirectory(files[0], this.configuration.getCatalinaBase()); }
From source file:io.fabric8.tooling.archetype.ArchetypeUtils.java
/** * Recursively looks for first nested directory which contains at least one source file * * @param directory/*from ww w .jav a 2 s .co m*/ * @return */ public File findRootPackage(File directory) throws IOException { if (!directory.isDirectory()) { throw new IllegalArgumentException( "Can't find package inside file. Argument should be valid directory."); } File[] children = directory.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return isValidSourceFileOrDir(pathname); } }); if (children != null) { List<File> results = new LinkedList<File>(); for (File it : children) { if (!it.isDirectory()) { // we have file - let's assume we have main project's package results.add(directory); break; } else { File pkg = findRootPackage(it); if (pkg != null) { results.add(pkg); } } } if (results.size() == 1) { return results.get(0); } else { return directory; } } return null; }