List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:com.siemens.scr.avt.ad.io.BatchLoader.java
public void loadFromDirectory(File directory) throws Exception { preprocess(FileUtils.iterateFiles(directory, new SuffixFileFilter(getSuffix()), TrueFileFilter.INSTANCE)); load(FileUtils.iterateFiles(directory, new SuffixFileFilter(getSuffix()), TrueFileFilter.INSTANCE)); }
From source file:com.chingo247.structureapi.plan.document.PlanDocumentGenerator.java
public void generate(File targetFolder) { // Scan the folder called 'SchematicToPlan' for schematic files Iterator<File> it = FileUtils.iterateFiles(targetFolder, new String[] { "schematic" }, true); System.out.println("Files: " + targetFolder.listFiles().length); int count = 0; long start = System.currentTimeMillis(); // Generate Plans while (it.hasNext()) { File schematic = it.next(); Document d = DocumentHelper.createDocument(); d.addElement(Elements.ROOT).addElement(Elements.SETTLERCRAFT).addElement(Elements.SCHEMATIC) .setText(schematic.getName()); File plan = new File(schematic.getParent(), FilenameUtils.getBaseName(schematic.getName()) + ".xml"); try {//from w w w . j ava 2 s .c o m XMLWriter writer = new XMLWriter(new FileWriter(plan)); writer.write(d); writer.close(); StructurePlan sp = new StructurePlan(); PlanDocument pd = new PlanDocument(structureAPI.getPlanDocumentManager(), plan); pd.putPluginElement("SettlerCraft", new PlanDocumentPluginElement("SettlerCraft", pd, (Element) d.selectSingleNode("StructurePlan/SettlerCraft"))); sp.load(pd); if (sp.getCategory().equals("Default") && !schematic.getParentFile().getName().equals(targetFolder.getName())) { sp.setCategory(schematic.getParentFile().getName()); } sp.save(); } catch (DocumentException ex) { Logger.getLogger(StructurePlanManager.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | StructureDataException ex) { Logger.getLogger(StructurePlanManager.class.getName()).log(Level.SEVERE, null, ex); } count++; } if (count > 0) { StructureAPI.print("Generated " + count + " plans in " + (System.currentTimeMillis() - start) + "ms"); } }
From source file:gov.nih.nci.sdk.example.generator.util.GeneratorUtil.java
public static String getFiles(String _dir, String[] _extensions, String _separator) { java.util.logging.Logger.getLogger("DEBUG").info("Directory _dir is: " + _dir); StringBuffer files = new StringBuffer(); try {//w ww. j a va 2 s . co m Iterator iter = FileUtils.iterateFiles(new File(_dir), _extensions, false); while (iter.hasNext() == true) { File file = (File) iter.next(); files.append(file.getAbsolutePath()).append(_separator); } } catch (Throwable t) { throw new RuntimeException(t); } java.util.logging.Logger.getLogger("DEBUG").info("Returning these files: " + files); return files.toString().replaceAll(":$", ""); }
From source file:it.geosolutions.geobatch.settings.GBSettingsDAOXStreamImpl.java
public List<String> getIds() { List<String> ret = new ArrayList<String>(); final Iterator<File> it = FileUtils.iterateFiles(settingsDir, new String[] { ".xml" }, false); while (it.hasNext()) { File file = it.next();/*from w w w . jav a 2 s. c om*/ String name = FilenameUtils.getBaseName(file.getName()); ret.add(name); } return ret; }
From source file:gov.nih.nci.restgen.util.GeneratorUtil.java
public static String getFiles(String _dir, String[] _extensions, String _separator) { StringBuffer files = new StringBuffer(); try {//from w w w .j a v a2 s .c o m Iterator iter = FileUtils.iterateFiles(new File(_dir), _extensions, false); while (iter.hasNext() == true) { File file = (File) iter.next(); files.append(file.getAbsolutePath()).append(_separator); } } catch (Throwable t) { throw new RuntimeException(t); } return files.toString().replaceAll(":$", ""); }
From source file:com.chingo247.structureapi.plan.document.PlanDocumentManager.java
/** * Loads all planDocuments & structureDocuments Multi-Core. Number of cores used is defined by * the number of cores available using Runtime.getRuntime.availableProcessors() *//*from ww w . j a va 2s . co m*/ @Override public synchronized void loadDocuments() { // Go throug all XML files inside the 'Plans' folder Iterator<File> it = FileUtils.iterateFiles(structureAPI.getPlanDataFolder(), new String[] { "xml" }, true); final List<Future> tasks = new LinkedList<>(); while (it.hasNext()) { final File planDocFile = it.next(); tasks.add(executor.submit(new Runnable() { @Override public void run() { try { SAXReader reader = new SAXReader(); Document d = reader.read(planDocFile); // If the RootElement is not 'StructurePlan', skip it if (!isStructurePlan(d)) { return; } List<Element> elements = d.getRootElement().elements(); // Form plan document PlanDocument planDocument = new PlanDocument(PlanDocumentManager.this, planDocFile); for (Element pluginElement : elements) { planDocument.putPluginElement(pluginElement.getName(), new PlanDocumentPluginElement( pluginElement.getName(), planDocument, pluginElement)); } // Save the document PlanDocumentManager.this.put(planDocument.getRelativePath(), planDocument); } catch (DocumentException ex) { Logger.getLogger(PlanDocumentManager.class.getName()).log(Level.SEVERE, null, ex); } } })); } // Block until all tasks are done for (Future f : tasks) { try { f.get(); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(PlanDocumentManager.class.getName()).log(Level.SEVERE, null, ex); for (Future fu : tasks) { fu.cancel(true); } } } }
From source file:com.sindicetech.siren.demo.movie.MovieDemo.java
public void index() throws IOException { final SimpleIndexer indexer = new SimpleIndexer(indexDir); try {//from w ww . jav a 2s . c om final Iterator<File> it = FileUtils.iterateFiles(MOVIE_PATH, null, false); while (it.hasNext()) { final File file = it.next(); final String id = file.getName().toString(); final String content = FileUtils.readFileToString(file); logger.info("Indexing document {}", id); indexer.addDocument(id, content); } logger.info("Commiting all pending documents"); indexer.commit(); } finally { logger.info("Closing index"); indexer.close(); } }
From source file:com.github.born2snipe.maven.plugin.idea.sandbox.CopyPluginToPluginSandboxMojo.java
private void copyClassesToSandbox() { getLog().info("Copying classes to sandbox"); File classesSandbox = new File(projectSandboxDirectory(), "classes"); classesSandbox.mkdirs();/*www . j av a 2 s. c om*/ File outputDirectory = new File(project.getBuild().getOutputDirectory()); Iterator<File> iterator = FileUtils.iterateFiles(outputDirectory, null, true); while (iterator.hasNext()) { File file = iterator.next(); if ("plugin.xml".equals(file.getName())) { continue; } String newPath = file.getAbsolutePath().replace(outputDirectory.getAbsolutePath(), ""); File classFileDestination = new File(classesSandbox, newPath); copyFileTo(file, classFileDestination.getParentFile()); } }
From source file:mx.itesm.imb.EcoreImbEditor.java
/** * /*from ww w.j a v a2 s .c om*/ * @param ecoreProject */ @SuppressWarnings("unchecked") public static void generateProvidersArtifacts(final File ecoreProject, final File templateProject) { File provider; File imbProject; List<File> imbTypes; Iterator<File> files; List<String> types; String typesPackage; // Get imb types imbProject = new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit"); files = FileUtils.iterateFiles(new File(imbProject, "/src/imb"), new String[] { "java" }, true); imbTypes = new ArrayList<File>(); while (files.hasNext()) { imbTypes.add(files.next()); } // Get providers files files = FileUtils.iterateFiles(imbProject, new IOFileFilter() { @Override public boolean accept(final File file) { return file.getName().endsWith("ItemProvider.java"); } @Override public boolean accept(File directory, String file) { return file.endsWith("ItemProvider.java"); } }, TrueFileFilter.INSTANCE); typesPackage = null; types = new ArrayList<String>(); while (files.hasNext()) { try { provider = files.next(); types.add(provider.getName().replace("ItemProvider.java", "")); typesPackage = provider.getPath() .substring(provider.getPath().indexOf("src") + "src".length() + 1, provider.getPath().indexOf(provider.getName().replace(".java", "")) - 1) .replace('/', '.'); EcoreImbEditor.writeEcoreAspect(provider, imbTypes); EcoreImbEditor.writeEcoreController(imbProject, templateProject, provider, imbTypes); System.out.println("Artifacts for " + provider + " successfully generated"); } catch (Exception e) { e.printStackTrace(); System.out.println("Error generating Artifacts: " + e.getMessage()); } } // Configuration properties file try { FileUtils.copyFile(new File(templateProject, "/templates/configuration-template.properties"), new File(imbProject, "/src/mx/itesm/imb/configuration.properties")); FileUtils.copyFile(new File(templateProject, "/templates/configuration-template.properties"), new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/src/mx/itesm/imb/configuration.properties")); } catch (IOException e) { System.out.println("Unable to generate configuration properties file: " + e.getMessage()); } // Selection aspect typesPackage = typesPackage.replace(".provider", ""); EcoreImbEditor.writeSelectionAspect(ecoreProject, typesPackage, types); }
From source file:de.micromata.genome.db.jpa.genomecore.chronos.JobStoreTest.java
License:asdf
public void findClassPathInJars() { try {//from ww w . ja va 2s . c o m Iterator it = FileUtils.iterateFiles(new File("."), new String[] { "jar" }, true); for (; it.hasNext();) { File f = (File) it.next(); ZipInputStream zf = new ZipInputStream(new FileInputStream(f)); ZipEntry ze; while ((ze = zf.getNextEntry()) != null) { String name = ze.getName(); if (name.startsWith("org/objectweb/asm") == true) { System.out.println("Found: " + f.getCanonicalPath()); zf.closeEntry(); break; } zf.closeEntry(); } zf.close(); } } catch (Exception ex) { throw new RuntimeException(ex); } }