List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:es.uvigo.ei.sing.adops.datatypes.SingleExperiment.java
@Override public boolean isClean() { if (this.hasResult()) { return false; } else {//from w w w . j a v a 2 s . com final FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.equals(SingleExperiment.this.getNotesFile()) || pathname.equals(SingleExperiment.this.getPropertiesFile()) || pathname.equals(SingleExperiment.this.getFastaFile()) || pathname.equals(SingleExperiment.this.getNamesFile())) { return false; } else if (pathname.equals(SingleExperiment.this.getFilesFolder())) { return pathname.listFiles().length != 0; } return true; } }; return this.getFolder().listFiles(filter).length > 0; } }
From source file:net.sf.firemox.Magic.java
/** * Creates new form Magic/*from w ww.j a v a 2 s . co m*/ */ private Magic() { super(); initComponents(); // list all installed Look&Feel UIListener uiListener = new UIListener(); UIManager.LookAndFeelInfo[] uimTMP = UIManager.getInstalledLookAndFeels(); final List<Pair<String, String>> lfList = new ArrayList<Pair<String, String>>(); for (LookAndFeelInfo lookAndFeel : uimTMP) { Pair<String, String> info = new Pair<String, String>(lookAndFeel.getName(), lookAndFeel.getClassName()); if (!lfList.contains(info)) { lfList.add(info); } } // list all SkinLF themes final File[] themes = MToolKit.getFile("lib").listFiles(new FileFilter() { public boolean accept(File f) { return f != null && f.getName().endsWith(".zip"); } }); int maxIndex = Configuration.getConfiguration().getMaxIndex("themes.skinlf.caches.cache"); List<Pair<String, String>> knownThemes = new ArrayList<Pair<String, String>>(); for (int i = 0; i < maxIndex + 1; i++) { String file = Configuration.getConfiguration() .getString("themes.skinlf.caches.cache(" + i + ").[@file]"); int index = ArrayUtils.indexOf(themes, MToolKit.getFile(file)); if (index >= 0) { themes[index] = null; Pair<String, String> skin = new Pair<String, String>( Configuration.getConfiguration().getString("themes.skinlf.caches.cache(" + i + ").[@name]"), file); knownThemes.add(skin); lfList.add(skin); } } for (File theme : themes) { if (theme != null) { // a new theme --> will be cached try { final List<Node> properties = new XmlParser().parse(new ZipResourceLoader(theme.toURI().toURL()) .getResourceAsStream("skinlf-themepack.xml")).getNodes("property"); PROPERTIES: for (int j = 0; j < properties.size(); j++) { if ("skin.name".equals(properties.get(j).getAttribute("name"))) { // skin name found String relativePath = MToolKit.getRelativePath(theme.getCanonicalPath()); Pair<String, String> skin = new Pair<String, String>( properties.get(j).getAttribute("value"), "zip:" + relativePath); lfList.add(skin); knownThemes.add(new Pair<String, String>(properties.get(j).getAttribute("value"), relativePath)); break PROPERTIES; } } } catch (Exception e) { Log.error("Error in " + theme, e); } } } Configuration.getConfiguration().clearProperty("themes.skinlf.caches"); for (int index = 0; index < knownThemes.size(); index++) { Pair<String, String> skin = knownThemes.get(index); Configuration.getConfiguration().setProperty("themes.skinlf.caches.cache(" + index + ").[@name]", skin.key); Configuration.getConfiguration().setProperty("themes.skinlf.caches.cache(" + index + ").[@file]", skin.value); } // create look and feel menu items Collections.sort(lfList); lookAndFeels = new JRadioButtonMenuItem[lfList.size() + 1]; ButtonGroup group5 = new ButtonGroup(); for (int i = 0; i < lfList.size(); i++) { final String lfName = lfList.get(i).key; final String lfClassName = lfList.get(i).value; lookAndFeels[i] = new JRadioButtonMenuItem(lfName); if (lookAndFeelName.equalsIgnoreCase(lfClassName)) { // this the current l&f lookAndFeels[i].setSelected(true); } if (!SkinLF.isSkinLF(lfClassName)) { lookAndFeels[i].setEnabled(MToolKit.isAvailableLookAndFeel(lfClassName)); } group5.add(lookAndFeels[i]); lookAndFeels[i].setActionCommand(lfClassName); themeMenu.add(lookAndFeels[i], i); lookAndFeels[i].addActionListener(uiListener); } lfList.clear(); initialdelayMenu.addActionListener(this); dismissdelayMenu.addActionListener(this); ConnectionManager.enableConnectingTools(false); // read auto mana option MCommonVars.autoMana = Configuration.getBoolean("automana", true); autoManaMenu.setSelected(MCommonVars.autoMana); // Force to initialize the TBS settings MToolKit.tbsName = null; setMdb(Configuration.getString("lastTBS", IdConst.TBS_DEFAULT)); // set the autoStack mode MCommonVars.autoStack = Configuration.getBoolean("autostack", false); autoPlayMenu.setSelected(MCommonVars.autoStack); // read maximum displayed colored mana in context PayMana.thresholdColored = Configuration.getInt("threshold-colored", 6); ZoneManager.updateLookAndFeel(); // pack this frame pack(); // Maximize this frame setExtendedState(Frame.MAXIMIZED_BOTH); if (batchMode != -1) { final String deckFile = Configuration.getString(Configuration.getString("decks.deck(0)")); try { Deck batchDeck = DeckReader.getDeck(this, deckFile); switch (batchMode) { case BATCH_SERVER: ConnectionManager.server = new Server(batchDeck, null); ConnectionManager.server.start(); break; case BATCH_CLIENT: ConnectionManager.client = new Client(batchDeck, null); ConnectionManager.client.start(); break; default: } } catch (Throwable e) { throw new RuntimeException("Error in batch mode : ", e); } } }
From source file:it.jnrpe.plugins.factory.CPluginFactory.java
/** * @deprecated/* w w w . j a v a 2 s. co m*/ */ private void configurePlugins(File fDir) { m_Logger.trace("READING PLUGIN CONFIGURATION FROM DIRECTORY " + fDir.getName()); CStreamManager streamMgr = new CStreamManager(); File[] vfJars = fDir.listFiles(new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(".jar"); } }); // Initializing classloader URL[] urls = new URL[vfJars.length]; URLClassLoader ul = null; for (int j = 0; j < vfJars.length; j++) { try { urls[j] = vfJars[j].toURI().toURL(); } catch (MalformedURLException e) { // should never happen } } ul = URLClassLoader.newInstance(urls); for (int i = 0; i < vfJars.length; i++) { File file = vfJars[i]; try { m_Logger.info("READING PLUGINS DATA IN FILE '" + file.getName() + "'"); ZipInputStream jin = (ZipInputStream) streamMgr .handle(new ZipInputStream(new FileInputStream(file))); ZipEntry ze = null; while ((ze = jin.getNextEntry()) != null) { if (ze.getName().equals("plugin.xml")) { parsePluginXmlFile(jin); break; } } } catch (Exception e) { m_Logger.error("UNABLE TO READ DATA FROM FILE '" + file.getName() + "'. THE FILE WILL BE IGNORED.", e); } finally { streamMgr.closeAll(); } } }
From source file:com.adito.notification.Notifier.java
void loadFromDisk() throws IOException { File[] f = queueDirectory.listFiles(new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(".msg"); }/* ww w . j av a 2s . co m*/ }); // TODO better error handling in parsing of message files. Report on // non-existant / unreadable directory if (f == null) { throw new IOException("Could not list queue directory " + queueDirectory.getAbsolutePath()); } for (int i = 0; i < f.length; i++) { FileInputStream fin = new FileInputStream(f[i]); try { DataInputStream din = new DataInputStream(fin); long id = din.readLong(); String sinkName = din.readUTF(); messageId = Math.max(id, messageId); boolean urgent = din.readBoolean(); String subject = din.readUTF(); List<Recipient> recipientList = new ArrayList<Recipient>(); while (true) { int recipientType = din.readInt(); if (recipientType == Recipient.EOF) { break; } else { String recipientAlias = din.readUTF(); String realmName = din.readUTF(); Recipient recipient = new Recipient(recipientType, recipientAlias, realmName); recipientList.add(recipient); } } Properties parameters = new Properties(); while (true) { int parameterType = din.readInt(); if (parameterType < 1) { break; } else { String key = din.readUTF(); String val = din.readUTF(); parameters.setProperty(key, val); } } String content = din.readUTF(); String lastMessage = din.readUTF(); Message msg = new Message(subject, content, urgent); msg.setId(id); msg.setRecipients(recipientList); msg.setSinkName(sinkName); msg.setLastMessage(lastMessage); queue(msg); } finally { fin.close(); } } }
From source file:au.edu.unsw.cse.soc.federatedcloud.curator.CuratorAPI.java
private List<CloudResourceDescription> queryKnowledgeBase(String query) { File folder = new File(KB_LOCATION); File[] jsonFiles = folder.listFiles(new FileFilter() { @Override/*ww w .ja v a 2 s . c o m*/ public boolean accept(File pathname) { System.out.println(pathname.getName()); return pathname.getName().endsWith(".json"); } }); List<CloudResourceDescription> descs = new ArrayList<CloudResourceDescription>(); if (jsonFiles == null) { try { throw new FileNotFoundException("No Resource descriptions found at:" + KB_LOCATION); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); return descs; //Returns a zero length List } } else { for (File file : jsonFiles) { if (file.isDirectory()) { continue; } try { CloudResourceDescription desc = DataModelUtil.buildCouldResourceDescriptionFromJSON(file); descs.add(desc); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } System.out.println("Size of Descriptions:" + descs.size()); return descs; } }
From source file:de.tudarmstadt.lt.lm.app.FilterLines.java
@Override public void run() { _pout = System.out;//ww w. j av a 2 s. c om 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 ('{}').", _file); try { run(new InputStreamReader(System.in, "UTF-8")); } catch (Exception e) { LOG.error("Could not process file '{}'.", _file, e); } } else { File f_or_d = new File(_file); if (!f_or_d.exists()) throw new Error(String.format("File or directory '%s' not found.", _file)); if (f_or_d.isFile()) { LOG.info("Processing file '{}'.", f_or_d.getAbsolutePath()); try { run(new InputStreamReader(new FileInputStream(f_or_d), "UTF-8")); } catch (Exception e) { LOG.error("Could not process file '{}'.", 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 '{}' ({}/{}).", f.getAbsolutePath(), i + 1, txt_files.length); try { run(new InputStreamReader(new FileInputStream(f), "UTF-8")); } catch (Exception e) { LOG.error("Could not process file '{}'.", f.getAbsolutePath(), e); } } } } }
From source file:org.zols.templates.service.TemplateRepositoryService.java
private void listTemplateFiles(List<Map<String, String>> templateFiles, String rootPath, File folder) { File[] files = folder.listFiles(new FileFilter() { @Override/*from ww w . j a va 2s . co m*/ public boolean accept(File pathname) { return pathname.isDirectory() || pathname.getName().endsWith(".html"); } }); for (File file : files) { if (file.isDirectory()) { listTemplateFiles(templateFiles, rootPath, file); } else { Map<String, String> map = new HashMap<>(1); String filePath = file.getAbsolutePath().substring(rootPath.length()); map.put("label", filePath); map.put("value", filePath.replaceAll(".html", "")); templateFiles.add(map); } } }
From source file:de.kaiserpfalzEdv.maven.apacheds.config.LdifLoader.java
private void loadLdifsFromSubdirectories(final File directory) throws FileNotFoundException, LdapException, MojoExecutionException { for (File ldifDirectory : directory.listFiles(new FileFilter() { @Override// w ww . j a v a2 s.c om public boolean accept(final File pathname) { return pathname.isDirectory(); } })) { loadLdif(ldifDirectory); } }
From source file:org.alfresco.repo.bulkimport.CreateInPlaceTestData.java
private void initSourceFiles(File sourceFolder) { for (File f : sourceFolder.listFiles(new FileFilter() { @Override/*w ww. jav a2s. c o m*/ public boolean accept(File file) { return !file.getName().startsWith("."); } })) { sourceFiles.add(f); } }
From source file:JarBuilder.java
/** Add the directory into the directory specified by parent * @param dir the directory to add//from ww w .j a va 2 s. c o m * @param parent the path inside the jar that the directory should be added to */ public void addDirectoryRecursive(File dir, String parent) { addDirectoryRecursiveHelper(dir, parent, new byte[2048], new FileFilter() { public boolean accept(File pathname) { return true; } }); }