List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:biz.paluch.maven.configurator.FileTemplating.java
/** * Process files which match the template pattern. Creates a new file using the input file with property * replacement. Target filename is without the template name part. * * @param log/* ww w.j av a2 s . c o m*/ * @param root * @param processor * @throws IOException */ public static void processFiles(Log log, File root, TemplateProcessor processor) throws IOException { Iterator<File> iterator = FileUtils.iterateFiles(root, new RegexFileFilter(FILE_TEMPLATE_PATTERN), TrueFileFilter.TRUE); while (iterator.hasNext()) { File next = iterator.next(); log.debug("Processing file " + next); try { processor.processFile(next, getTargetFile(next)); } catch (IOException e) { throw new IOException("Cannot process file " + next.toString() + ": " + e.getMessage(), e); } } }
From source file:gov.nih.nci.sdk.example.generator.util.GeneratorUtil.java
public static List getFiles(String _dir, String[] _extensions) { java.util.logging.Logger.getLogger("DEBUG").info("Directory _dir is: " + _dir); List<String> files = new ArrayList(); try {//from w w w . j a va 2 s . com Iterator iter = FileUtils.iterateFiles(new File(_dir), _extensions, false); while (iter.hasNext() == true) { File file = (File) iter.next(); files.add(file.getAbsolutePath()); } } catch (Throwable t) { throw new RuntimeException(t); } java.util.logging.Logger.getLogger("DEBUG").info("Returning these files: " + files); return files; }
From source file:com.cloudhopper.commons.io.demo.FileServerMain.java
public static void loadFilesFromDir(String dir, int threads) { ThreadPoolExecutor ex = new ThreadPoolExecutor(threads, threads, 5000l, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); ex.prestartAllCoreThreads();//ww w.ja va 2 s . co m IdGenerator idGen = new UUIDIdGenerator(); final FileStore store = new SimpleNIOFileStore(idGen, "/tmp/fileStore/"); final long start = System.currentTimeMillis(); int count = 0; Iterator<File> it = FileUtils.iterateFiles(new File(dir), null, true); while (it.hasNext()) { final File f = it.next(); final int num = count++; Runnable job = new Runnable() { @Override public void run() { try { RandomAccessFile randomAccessFile = new RandomAccessFile(f, "r"); FileChannel fileChannel = randomAccessFile.getChannel(); Id id = store.write(fileChannel); System.out.println("(" + num + ") Stored " + f.getPath() + " as " + id.getName() + " after " + (System.currentTimeMillis() - start) + "ms"); } catch (Exception e) { logger.error("", e); } } }; ex.execute(job); } }
From source file:mongis.utils.ImageFinderTask.java
@Override protected List<File> call() throws Exception { ArrayList<File> files = new ArrayList<>(); Iterator<File> iterateFiles = FileUtils.iterateFiles(root, ImageFormatUtils.getSupportedExtensionsWithoutDot(), true); while (iterateFiles.hasNext()) { File f = iterateFiles.next(); files.add(f);/* w w w . j a v a 2 s . c om*/ updateMessage("File found :" + files.size()); } return files; }
From source file:mx.itesm.imb.ImbBusController.java
@SuppressWarnings("unchecked") public static void generateImbBusController(final File rooProject, final File busProject) { Writer writer;//from w ww .ja v a 2 s. c o m File typeReference; File controllerFile; int basePackageIndex; String imbTypePackage; String webConfiguration; VelocityContext context; Collection<String> types; String controllerPackage; Iterator<File> typesIterator; try { // Copy imb types FileUtils.copyDirectory(new File(rooProject, "/src/main/java/imb"), new File(busProject, "/src/main/java/imb")); FileUtils.copyFile(new File(rooProject, "/src/main/resources/schema.xsd"), new File(busProject, "/src/main/resources/schema.xsd")); imbTypePackage = null; types = new ArrayList<String>(); typesIterator = FileUtils.iterateFiles(new File(busProject, "/src/main/java/imb"), new String[] { "java" }, true); while (typesIterator.hasNext()) { typeReference = typesIterator.next(); if ((!typeReference.getName().equals("ObjectFactory.java")) && (!typeReference.getName().equals("package-info.java"))) { if (FileUtils.readFileToString(typeReference).contains("public class")) { types.add(typeReference.getName().replace(".java", "")); if (imbTypePackage == null) { imbTypePackage = typeReference.getPath() .substring( typeReference.getPath().indexOf("src/main/java") + "src/main/java".length() + 1, typeReference.getPath().indexOf(typeReference.getName()) - 1) .replace(File.separatorChar, '.'); } } } } // Add rest configuration FileUtils.copyFile( new File(rooProject, "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"), new File(busProject, "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml")); context = new VelocityContext(); context.put("types", types); context.put("imbTypePackage", imbTypePackage); webConfiguration = FileUtils .readFileToString(new File(busProject, "src/main/webapp/WEB-INF/spring/webmvc-config.xml")); basePackageIndex = webConfiguration.indexOf("base-package=\"") + "base-package=\"".length(); controllerPackage = webConfiguration.substring(basePackageIndex, webConfiguration.indexOf('"', basePackageIndex)) + ".web"; context.put("controllerPackage", controllerPackage); context.put("typePackage", controllerPackage.replace(".web", ".domain")); controllerFile = new File(busProject, "/src/main/java/" + controllerPackage.replace('.', '/') + "/ImbBusController.java"); writer = new FileWriter(controllerFile); ImbBusController.controllerTemplate.merge(context, writer); writer.close(); } catch (Exception e) { System.out.println("Error while configuring IMB Bus: " + e.getMessage()); } }
From source file:my.extensions.app.AudioFileLister.java
private String listFiles() { if (musicDirectoryReadable()) { File audioDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); Iterator<File> fileIterator = FileUtils.iterateFiles(audioDir, FILE_EXTS, true); List<FileInfo> files = new ArrayList<FileInfo>(); File f;//from www . j ava 2s. c o m while (fileIterator.hasNext()) { f = fileIterator.next(); files.add(new FileInfo(f)); } String filesJson = gson.toJson(files); return "{\"success\": true, \"files\": " + filesJson + "}"; } else { return "{\"success\": false, \"error\":\"audio directory not readable\"}"; } }
From source file:com.technophobia.substeps.runner.runtime.PredicatedClassLocator.java
public Iterator<Class<?>> fromPath(final String path) { final File directory = new File(path); final Iterator<File> files = FileUtils.iterateFiles(directory, new String[] { "class" }, true); final Iterator<Class<?>> unsafeTransformedClasses = Iterators.transform(files, classLoader); return Iterators.filter(unsafeTransformedClasses, Predicates.and(Predicates.notNull(), predicate)); }
From source file:gov.nih.nci.restgen.util.GeneratorUtil.java
public static List getFiles(String _dir, String[] _extensions) { List<String> files = new ArrayList(); try {//from w w w .j a v a 2 s . c o m Iterator iter = FileUtils.iterateFiles(new File(_dir), _extensions, true); while (iter.hasNext() == true) { File file = (File) iter.next(); files.add(file.getAbsolutePath()); } } catch (Throwable t) { throw new RuntimeException(t); } return files; }
From source file:com.pixlabs.web.utils.Mp3Finder.java
/** * @param path Path of the directory that should be looked into. * @return a linkedlist containing all the Mp3 files found in the directory and subdirectories. *///from w w w .java2s . co m public static LinkedList<Mp3FileAdvanced> mp3InDirectories(Path path) { Iterator it = FileUtils.iterateFiles(new File(path.toString()), new String[] { "mp3" }, true); LinkedList<Mp3FileAdvanced> mp3List = new LinkedList<>(); while (it.hasNext()) { File file = (File) it.next(); try { mp3List.add(new Mp3FileAdvanced(file)); } catch (InvalidDataException | IOException | UnsupportedTagException e) { e.printStackTrace(); } } return mp3List; }
From source file:FileInit.java
public void doJob() throws Exception { Logger.info("Creating required folders"); File readme = new File(ArtifactsController.getArtifactsFolder(), "README.md"); if (!readme.exists()) { FileUtils.touch(readme);// w w w .jav a 2 s .co m FileUtils.writeStringToFile(readme, "This is the local artifacts repository"); } // getting all files from the folder and adding them to the artifacts // repository if not already here... Iterator<File> iter = FileUtils.iterateFiles(ArtifactsController.getArtifactsFolder(), new String[] { "zip" }, false); while (iter.hasNext()) { File file = iter.next(); // find the artifact with the file name as URL if (!ArtifactURL.localExists(file.getName())) { ArtifactURL a = new ArtifactURL(); a.date = new Date(); a.local = true; a.name = file.getName(); a.url = file.getName(); a.save(); } else { Logger.info("Aleady registered " + file.getName()); } } }