List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:io.github.bonigarcia.wdm.BrowserManager.java
public String existsDriverInCache(String repository, String driverVersion, Architecture arch) { String driverInCache = null;//w w w. ja v a 2 s .c om for (String driverName : getDriverName()) { log.trace("Checking if {} {} ({} bits) exists in cache {}", driverName, driverVersion, arch, repository); Iterator<File> iterateFiles = FileUtils.iterateFiles(new File(repository), null, true); while (iterateFiles.hasNext()) { driverInCache = iterateFiles.next().toString(); // Exception for phantomjs boolean architecture = driverName.equals("phantomjs") || driverInCache.contains(arch.toString()); log.trace("Checking {}", driverInCache); if (driverInCache.contains(driverVersion) && driverInCache.contains(driverName) && architecture) { log.debug("Found {} {} ({} bits) in cache: {} ", driverVersion, driverName, arch, driverInCache); break; } else { driverInCache = null; } } if (driverInCache == null) { log.trace("{} {} ({} bits) do not exist in cache {}", driverVersion, driverName, arch, repository); } else { break; } } return driverInCache; }
From source file:debop4k.core.io.FilexTest.java
@Test @SneakyThrows/*from ww w . j ava2s.co m*/ public void discoverLatestFiles() { // 3? ? ?? ? . long since = DateTime.now().minusDays(5).getMillis(); String start = "."; boolean filtered = false; // Iterator<File> iter = FileUtils.iterateFiles(new File(start), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); Iterator<File> iter = FileUtils.iterateFiles(new File(start), new String[] { "class" }, true); while (iter.hasNext()) { File file = iter.next(); log.trace("file={}", file.getName()); if (!file.isDirectory()) { long filetime = file.lastModified(); log.trace("filetime={}, since={}", filetime, since); if (filetime > since) { filtered = file.getCanonicalPath().contains("FilexTest"); if (filtered) break; } } } assertThat(filtered).isTrue(); }
From source file:com.jhash.oimadmin.Utils.java
public static void createJarFileFromDirectory(String directory, String jarFileName) { File jarDirectory = new File(directory); try (JarOutputStream jarFileOutputStream = new JarOutputStream(new FileOutputStream(jarFileName))) { for (Iterator<File> fileIterator = FileUtils.iterateFiles(jarDirectory, null, true); fileIterator .hasNext();) {/*from www .j a va 2s . c o m*/ File inputFile = fileIterator.next(); String inputFileName = inputFile.getAbsolutePath(); String directoryFileName = jarDirectory.getAbsolutePath(); String relativeInputFileName = inputFileName.substring(directoryFileName.length() + 1); JarEntry newFileEntry = new JarEntry(relativeInputFileName); newFileEntry.setTime(System.currentTimeMillis()); jarFileOutputStream.putNextEntry(newFileEntry); jarFileOutputStream.write(FileUtils.readFileToByteArray(inputFile)); } } catch (Exception exception) { throw new OIMAdminException( "Failed to create the jar file " + jarFileName + " from directory " + directory, exception); } }
From source file:com.rhythm.louie.pbcompiler.PBCompilerMojo.java
@Override public void execute() throws MojoExecutionException { if (!cppgen && !pygen && !javagen) { getLog().warn("PB Compiler had nothing to run!"); return;// ww w.j av a 2 s. co m } //adjust directories according to basedir, and create if necessary if (javagen) { javadir = basedirectory + "/" + javadir; makeDir(javadir); } if (pygen) { pythondir = basedirectory + "/" + pythondir; makeDir(pythondir); } if (cppgen) { cppdir = basedirectory + "/" + cppdir; makeDir(cppdir); } List<String> args = new ArrayList<>(); args.add(compiler); args.add("--proto_path=" + basedirectory + "/" + protosrc); if (compilerInclude != null && compilerInclude.length > 0) { for (String dir : compilerInclude) { args.add("--proto_path=" + dir); } } else { // Try to find the google include in some known include dirs for (String dir : includeDirs) { File libdir = new File(dir + "/google"); if (libdir.exists()) { args.add("--proto_path=" + dir); } } } String archivePath = builddirectory + "/" + mavenSharedDir; File sharedArchive = new File(archivePath); if (sharedArchive.exists()) { args.add("--proto_path=" + archivePath); } if (javagen) args.add("--java_out=" + javadir); if (pygen) args.add("--python_out=" + pythondir); if (cppgen) args.add("--cpp_out=" + cppdir); //Find the proto files File dir = new File(basedirectory + "/" + protosrc); IOFileFilter filter = new WildcardFileFilter("**.proto"); Iterator<File> files = FileUtils.iterateFiles(dir, filter, TrueFileFilter.INSTANCE); while (files.hasNext()) { args.add(files.next().toString()); } try { execProtoCompile(args); } catch (IOException ex) { throw new MojoExecutionException(ex.toString()); } if (pygen) { //Generate __init__ files throughout tree where necessary Path pybase = Paths.get(pythondir); PlacePyInit pf = new PlacePyInit(); pf.start = pybase; try { Files.walkFileTree(pybase, pf); } catch (IOException ex) { getLog().error(ex.toString()); } } if (javagen) { //Add the gen'ed java dir back into maven resources getLog().debug("Injecting the Java PB dir into the compile time source root"); project.addCompileSourceRoot(javadir); } }
From source file:net.agkn.field_stripe.FileRecordEncoder.java
/** * Parse all Protobuf (*.proto) files in the specified path. *//*from w w w. j av a 2 s .c o m*/ public static List<Proto> parseProtobufDefinitions(final File protobufPath) { final List<Proto> protobufDefinitions = new ArrayList<Proto>(); final Iterator<File> protobufFiles = FileUtils.iterateFiles(protobufPath, new String[] { "proto" }, true/*recursively*/); while (protobufFiles.hasNext()) { final File protobufFile = protobufFiles.next(); if (protobufFile.isDirectory()) continue/*ignore directories*/; // CHECK: should this continue if there's an error parsing? try { protobufDefinitions.add(ProtoUtil.parseProto(protobufFile)); } catch (final RuntimeException re) { System.err.println("An error occurred while parsing: " + protobufFile.getAbsolutePath()); System.err.println(re.getLocalizedMessage()); } } return protobufDefinitions; }
From source file:cc.recommenders.io.Directory.java
public Set<String> findFiles(Predicate<String> predicate) { IOFileFilter fileFilter = new AbstractFileFilter() { @Override//from ww w . ja v a 2 s . c o m public boolean accept(File file) { return predicate.apply(file.getAbsolutePath()); } }; IOFileFilter allDirs = FileFilterUtils.trueFileFilter(); Iterator<File> it = FileUtils.iterateFiles(new File(rootDir), fileFilter, allDirs); Set<String> files = Sets.newLinkedHashSet(); while (it.hasNext()) { String absPath = it.next().getAbsolutePath(); String relPath = absPath.substring(rootDir.length()); // TODO -1? if (relPath.startsWith(File.separator)) { relPath = relPath.substring(1); } files.add(relPath); } return files; }
From source file:de.fhg.iais.asc.workflow.ASCTransform.java
private void executeTransformations(final TransformationContext transContext, AscContext parentAscContext) { StopWatch s = StopWatch.start();//from w w w. jav a 2s . c om final int maxFileCount = this.config.get(AscConfiguration.MAX_FILES_EACH, Integer.MAX_VALUE); int remainingFileCount = maxFileCount; final AbstractTransformer transformer = this.maker.getRootTransformer(); final TransformDocContextImpl transDocContext = new TransformDocContextImpl(transContext, this.maker.getInputSchema()); final TransformDocBuilder builder = new TransformDocBuilder().withContext(transDocContext); final File root = transDocContext.getInboxRoot().getAbsoluteFile(); final Iterator<File> fileIter = FileUtils.iterateFiles(root, INBOX_EXTENSIONS, true); while (fileIter.hasNext()) { if (--remainingFileCount < 0) { LOG.info("Transformation stopped by " + AscConfiguration.MAX_FILES_EACH + "=" + maxFileCount, parentAscContext); break; } final File f = fileIter.next(); final String relativePath = PathNameUtils.unbase(f, root); AscContext ascContext = new AscContext(ILogVocabulary.INPUT + "(" + relativePath + ")", parentAscContext); try { final TransformDoc transformDoc = builder.withPath(relativePath).build(); try { transformer.transform(transformDoc, ascContext); } catch (AscSplitLimitExceededException e) { LOG.info(LogMessageBuilder.getMessage(e)); } } catch (Exception e) { transContext.getIngest().writeErrorSip(SECTION_TRANSFORM, relativePath, e); builder.withPath(relativePath).build().updateAscErrorLoggingStatistic(transformer.getName(), e); LOG.error(LogMessageBuilder.getMessage("Transformation of " + relativePath + " failed", ascContext), e); } } s.stop("Time used for transformations"); }
From source file:com.zotoh.maedr.etc.CmdSamples.java
private void create3s(File appdir, File src, String ptr, Properties props) throws Exception { File f, t = new File(appdir, SRC); String s, lang = props.getProperty("lang"); File j = new File(t, lang + "/demo/" + ptr); j.mkdirs();/*from w ww .j av a2s . com*/ FileUtils.copyDirectory(new File(src, ptr + "/" + lang), j, new NotFileFilter(new SuffixFileFilter(".mf"))); Iterator<File> it = FileUtils.iterateFiles(j, new SuffixFileFilter("." + lang), null); while (it.hasNext()) { f = it.next(); s = StreamUte.readFile(f, "utf-8"); s = strstr(s, "demo." + ptr + "." + lang, "demo." + ptr); StreamUte.writeFile(f, s, "utf-8"); } }
From source file:de.jflex.plugin.maven.JFlexMojo.java
/** * Generate java code of a parser from a lexer file. * /*from w ww .j a v a2 s . c o m*/ * If the {@code lexDefinition} is a directory, process all lexer files * contained within. * * @param lexDefinition * Lexer definiton file or directory to process. * @throws MojoFailureException * if the file is not found. * @throws MojoExecutionException */ @SuppressWarnings("unchecked") private void parseLexDefinition(File lexDefinition) throws MojoFailureException, MojoExecutionException { assert lexDefinition.isAbsolute() : lexDefinition; if (lexDefinition.isDirectory()) { // recursively process files contained within String[] extensions = { "jflex", "jlex", "lex", "flex" }; getLog().debug("Processing lexer files found in " + lexDefinition); Iterator<File> fileIterator = FileUtils.iterateFiles(lexDefinition, extensions, true); while (fileIterator.hasNext()) { File lexFile = fileIterator.next(); parseLexFile(lexFile); } } else { parseLexFile(lexDefinition); } }
From source file:com.mindquarry.desktop.workspace.SVNSynchronizer.java
/** * Like synchronize(), but does a checkout if <tt>localPath</tt> isn't a * checkout. Also, creates the path if it doesn't exist. * /*from ww w . j a v a 2 s. co m*/ * @throws SynchronizeException */ // TODO: make a difference between user cancelled and synch aborted due // to some other error public void synchronizeOrCheckout() throws SynchronizeException { log.debug("synchronizeOrCheckout on " + localPathFile.getAbsolutePath()); // if directory doesn't exist, create it: if (!localPathFile.exists()) { boolean createdDir = localPathFile.mkdirs(); if (!createdDir) { throw new RuntimeException("Could not create directory: " + localPathFile.getAbsolutePath()); } } if (localPathFile.isFile()) { throw new IllegalArgumentException( "File where directory " + "was expected: " + localPathFile.getAbsolutePath()); } boolean isCheckedOut = isCheckedOut(localPathFile); if (isCheckedOut) { // already check out, sync it synchronize(); } else { // check if the directories are empty, // otherwise we'd try to check out into a directory // that contains local files already which causes // confusion. Iterator iter = FileUtils.iterateFiles(localPathFile, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); if (iter.hasNext()) { throw new SynchronizeException("Cannot initially checkout into '" + localPathFile.getAbsolutePath() + "' because it seems not empty."); } else { try { log.debug("checkout " + repositoryURL + " to " + localPathFile.getAbsolutePath()); client.checkout(repositoryURL, localPathFile.getAbsolutePath(), Revision.HEAD, true); } catch (ClientException e) { throw new RuntimeException( "Checkout of " + repositoryURL + " to " + localPathFile.getAbsolutePath() + " failed", e); } } } }