List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:snake.server.PathUtils.java
public static ArrayList<PathDescriptor> getRelativePathDescriptors(File folder, boolean useSystemCreationTime) { ArrayList<PathDescriptor> descriptors = new ArrayList<PathDescriptor>(); Iterator<File> filesIter = FileUtils.iterateFiles(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); while (filesIter.hasNext()) { Path folderPath = folder.toPath(); File file = filesIter.next(); Path filePath = file.toPath().toAbsolutePath(); Path relativePath = folderPath.relativize(filePath); PathDescriptor descriptor = new PathDescriptor(); descriptor.relative_path = FilenameUtils.separatorsToUnix(relativePath.toString()); descriptor.status = PathDescriptor.Status.Modified; descriptor.statusTimePoint = new Date(); descriptor.lastModified = new Date(file.lastModified()); if (useSystemCreationTime) { BasicFileAttributes attributes = null; try { attributes = Files.readAttributes(filePath, BasicFileAttributes.class); descriptor.lastCreationTime = new Date(attributes.creationTime().toMillis()); } catch (Exception e) { descriptor.lastCreationTime = descriptor.statusTimePoint; }/*w w w . j a v a2 s .c o m*/ } else { descriptor.lastCreationTime = descriptor.statusTimePoint; } descriptors.add(descriptor); } return descriptors; }
From source file:tv.phantombot.PhantomBot.java
/** * Backup the database, keeping so many days. *///from ww w. j av a 2 s. com private void doBackupSQLiteDB() { if (!dataStoreType.equals("sqlite3store")) { return; } ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate(() -> { Thread.currentThread().setName("tv.phantombot.PhantomBot::doBackupSQLiteDB"); SimpleDateFormat datefmt = new SimpleDateFormat("ddMMyyyy.hhmmss"); datefmt.setTimeZone(TimeZone.getTimeZone(timeZone)); String timestamp = datefmt.format(new Date()); dataStore.backupSQLite3("phantombot.auto.backup." + timestamp + ".db"); try { Iterator dirIterator = FileUtils.iterateFiles(new File("./dbbackup"), new WildcardFileFilter("phantombot.auto.*"), null); while (dirIterator.hasNext()) { File backupFile = (File) dirIterator.next(); if (FileUtils.isFileOlder(backupFile, (System.currentTimeMillis() - (long) (backupSQLiteKeepDays * 864e5)))) { FileUtils.deleteQuietly(backupFile); } } } catch (Exception ex) { com.gmt2001.Console.err.println("Failed to clean up database backup directory: " + ex.getMessage()); } }, 0, backupSQLiteHourFrequency, TimeUnit.HOURS); }
From source file:uk.ac.stfc.isis.ibex.opis.OpiProvider.java
public Collection<String> getOpiList() { Collection<String> relativeFilePaths = new ArrayList<String>(); Path root = pathToFileResource("/resources/"); Iterator<File> itr = FileUtils.iterateFiles(root.toFile(), new SuffixFileFilter(".opi"), TrueFileFilter.INSTANCE);//w w w.j a va 2 s .c o m while (itr.hasNext()) { Path path = new Path(itr.next().getAbsolutePath()); relativeFilePaths.add(path.makeRelativeTo(root).toString()); } return relativeFilePaths; }
From source file:uk.ac.ucl.cs.cmic.giftcloud.uploader.XmlFileImporter.java
public boolean importFiles(final File fileOrDirectory, final Progress progress) throws IOException, DicomException { boolean anyFiles = false; // Check if we are importing a file or directory. For a directory we import all files recursively if (fileOrDirectory.isDirectory()) { Iterator it = FileUtils.iterateFiles(fileOrDirectory, new String[] { "xml" }, true); while (it.hasNext()) { final File nextXmlFile = (File) it.next(); anyFiles = importXmlFile(progress, nextXmlFile) || anyFiles; }//from w w w . j av a 2 s. c om } else { if (fileOrDirectory.isFile() && FilenameUtils.isExtension(fileOrDirectory.getName(), "xml")) { anyFiles = importXmlFile(progress, fileOrDirectory) || anyFiles; } } return anyFiles; }
From source file:uniol.apt.tasks.IntegrationTestTask.java
/** * Program entry point. Arguments are program to run and directory to scan. * @param args Program arguments.//from ww w .j a v a 2 s. co m * @throws Exception In case something goes wrong. */ public static void main(String[] args) throws Exception { if (args.length != 2) throw new IllegalArgumentException("Need exactly two arguments: program to run, directory to scan"); String cmdline = args[0]; File directoryToScan = new File(args[1]); Iterator<File> fileIter = FileUtils.iterateFiles(directoryToScan, new WildcardFileFilter("*" + ARGS_SUFFIX), TrueFileFilter.INSTANCE); int count = 0; int failed = 0; while (fileIter.hasNext()) { count++; File file = fileIter.next(); try { if (!runTest(cmdline, file)) { failed++; System.out.println("Failure for " + file.getName()); } } catch (Exception e) { System.err.println("Exception occurred while parsing " + file.getAbsolutePath()); throw e; } } System.out.println("Successfully ran " + count + " integration tests"); if (failed != 0) { System.out.println(failed + " tests failed"); System.exit(1); } }
From source file:uniol.apt.tasks.ModuleParameterVerifyTask.java
/** * Program entry point. Arguments are a list of base directories and wildcards. * @param args Program arguments.// w w w . j a va 2 s. c om */ public static void main(String[] args) { if (args.length % 2 != 0) throw new IllegalArgumentException("Need base dir and wildcard pairs as arguments"); try { Map<String, ModuleParameterVerifyClassVisitor> classes = new HashMap<>(); for (int i = 0; i < args.length; i += 2) { String baseDir = args[i]; File baseFile = new File(baseDir); String wildcard = args[i + 1]; Iterator<File> fileIter = FileUtils.iterateFiles(baseFile, new WildcardFileFilter(wildcard), TrueFileFilter.INSTANCE); while (fileIter.hasNext()) { File classFile = fileIter.next(); ClassReader reader; try { reader = new ClassReader(FileUtils.openInputStream(classFile)); } catch (IOException ex) { throw new FailureException("Error accessing file: " + classFile, ex); } ModuleParameterVerifyClassVisitor cv = new ModuleParameterVerifyClassVisitor(); reader.accept(cv, 0); cv = classes.put(cv.getClassName(), cv); if (cv != null) throw new FailureException("Multiple definitions for class: " + cv.getClassName()); } } boolean fail = false; for (ModuleParameterVerifyClassVisitor cv : classes.values()) { fail |= analyseClass(cv, classes); } if (fail) { throw new FailureException( "Module parameter or return value use is incorrect; see above messages."); } } catch (FailureException e) { System.err.println(e.getMessage()); System.exit(1); } }
From source file:uniol.apt.tasks.WriteTestsXML.java
/** * Program entry point. Arguments are output directory, directory to scan and a file name pattern. * @param args Program arguments.//w w w . j ava 2 s . co m */ public static void main(String[] args) { if (args.length != 3) throw new IllegalArgumentException( "Need exactly three arguments: output file, directory to scan, file name pattern"); File outputFile = new File(args[0]); File directoryToScan = new File(args[1]); String namePattern = args[2]; Worker worker = new Worker(); Iterator<File> fileIter = FileUtils.iterateFiles(directoryToScan, new WildcardFileFilter(namePattern), TrueFileFilter.INSTANCE); while (fileIter.hasNext()) { File file = fileIter.next(); // The worker wants a relative path to the base directory String relativeFile = directoryToScan.toURI().relativize(file.toURI()).getPath(); try { worker.handleFile(relativeFile); } catch (UnhandledException e) { System.err.println("Could not handle file " + file + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } } try { worker.write(outputFile); } catch (FileNotFoundException | UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:waazdoh.client.storage.local.FileBeanStorage.java
private Iterator<File> getFileItarator(final String search) { return FileUtils.iterateFiles(new File(path), new IOFileFilter() { @Override/* w w w . jav a 2 s . c o m*/ public boolean accept(File f) { String path = f.getAbsolutePath().replace(File.separator, ""); log.info("fileiterator accept " + f); return path.indexOf(search) >= 0; } @Override public boolean accept(File arg0, String arg1) { log.info("not accepting " + arg0); return false; } }, new IOFileFilter() { @Override public boolean accept(File arg0, String arg1) { return true; } @Override public boolean accept(File arg0) { return true; } }); }