List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:com.collective.celos.WorkflowConfigurationParser.java
public WorkflowConfigurationParser parseConfiguration(File workflowsDir, StateDatabaseConnection connection) { LOGGER.info("Using workflows directory: " + workflowsDir); LOGGER.info("Using defaults directory: " + defaultsDir); Collection<File> files = FileUtils.listFiles(workflowsDir, new String[] { WORKFLOW_FILE_EXTENSION }, false); for (File f : files) { try {//from ww w. java 2 s .c o m parseFile(f, connection); } catch (Exception e) { LOGGER.error("Failed to load file: " + f + ": " + e.getMessage(), e); } } return this; }
From source file:io.apiman.manager.api.war.WarApiManagerBootstrapperServlet.java
/** * @see javax.servlet.GenericServlet#init() *//*from w ww. ja v a2 s .com*/ @Override public void init() throws ServletException { Thread t = new Thread(new Runnable() { @Override public void run() { // Wait 5s before doing this - hopefully dependencies will have started up by then try { Thread.sleep(5000); } catch (InterruptedException e1) { } File dataDir = getDataDir(); if (dataDir != null && dataDir.isDirectory()) { logger.debug("Checking for bootstrap files in " + dataDir); //$NON-NLS-1$ Collection<File> files = FileUtils.listFiles(dataDir, new String[] { "json" }, false); //$NON-NLS-1$ TreeSet<File> sortedFiles = new TreeSet<>(files); for (File file : sortedFiles) { File alreadyProcessed = new File(file.getAbsolutePath() + ".imported"); //$NON-NLS-1$ if (!alreadyProcessed.isFile()) { doImport(file); try { FileUtils.touch(alreadyProcessed); } catch (IOException e) { } } else { logger.debug("Skipping (already processed) file: " + file); //$NON-NLS-1$ } } } } }); t.setDaemon(true); t.start(); }
From source file:net.ripe.rpki.validator.util.TrustAnchorLocatorTest.java
@Test public void should_load_release_trust_anchor_locator_files() { Collection<File> tals = FileUtils.listFiles(new File("../rpki-validator-app/conf/tal"), new String[] { "tal" }, false); for (File file : tals) { TrustAnchorLocator.fromFile(file); }//from w w w.j a va 2 s. co m }
From source file:it.incipict.tool.profiles.ProfilesToolTest.java
@Test public void scanAllSurveys() { try {//from w ww . java2 s. co m for (File profileTypeKey : FileUtils.listFilesAndDirs(new File(TEST_RESOURCES), FalseFileFilter.FALSE, TrueFileFilter.TRUE)) { if (!profileTypeKey.getName().equals((new File(TEST_RESOURCES)).getName())) { StringBuilder report = new StringBuilder(); for (File survey : FileUtils.listFiles(new File(profileTypeKey + File.separator), extension, false)) { report.append("Analyzing " + survey.getAbsolutePath() + "\n"); Map<ProfileType, Double> checkProfile = profileTool.checkProfiles(survey); ProfileType bestProfile = ProfilesToolUtils.getBestProfile(checkProfile); Assert.assertEquals(profileTypeKey.getName(), bestProfile.getType()); report.append(ProfilesToolTestUtils.printDistancesToString(checkProfile) + "\n\n"); } FileUtils.writeStringToFile(new File(profileTypeKey + File.separator + "result.txt"), report.toString(), Charset.forName("ISO-8859-1")); } } Assert.assertTrue(true); } catch (ProfilesToolException | IOException e) { logger.error("error: ", e); Assert.assertTrue(false); } }
From source file:edu.lternet.pasta.auditmanager.AuditCleaner.java
/** * Removes any audit records XML file that is older than the specified * time-to-live (ttl).//from www . ja v a 2 s . c om * * @param ttl * The time-to-live value in milliseconds. */ public void doClean(Long ttl) { File tmpDir = new File(this.tmpDir); String[] ext = { "xml" }; Long time = new Date().getTime(); Long lastModified = null; Collection<File> files = FileUtils.listFiles(tmpDir, ext, false); for (File file : files) { if (file != null && file.exists()) { lastModified = file.lastModified(); // Remove file if older than the ttl if (lastModified + ttl <= time) { try { FileUtils.forceDelete(file); } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); } } } } }
From source file:com.centeractive.ws.builder.DefinitionSaveTest.java
public static List<String> getFileNames(File folder) { final boolean RECURSIVE = true; String[] extensions = new String[] { "wsdl", "xsd" }; Collection<File> files = FileUtils.listFiles(folder, extensions, RECURSIVE); List<String> fileNames = new ArrayList<String>(); for (File file : files) { fileNames.add(file.getName());//from w w w .j av a 2 s. com } return fileNames; }
From source file:ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory.java
private static void addToClassPath(List<File> classPathFiles, File dir, IOFileFilter fileFilter) { if (dir.isDirectory()) { for (File jar : FileUtils.listFiles(dir, fileFilter, null)) { classPathFiles.add(jar);/* ww w . j a v a 2 s. c o m*/ } } }
From source file:namedatabasescraper.MainWindow.java
private void populateNamesColumn() { String[] extensions = { "html", "htm" }; File dir = new File(this.jDirectoryNameTextField.getText()); if (dir.exists()) { this.htmlFiles = FileUtils.listFiles(dir, extensions, false); this.model = new DefaultTableModel(); model.setNumRows(htmlFiles.size()); model.setColumnCount(2);//from w w w . java 2s .c o m String[] columnNames = { "File Names", "Number of Words Extracted" }; model.setColumnIdentifiers(columnNames); int rowCount = 0; for (File htmlFile : this.htmlFiles) { model.setValueAt(htmlFile.getName(), rowCount, 0); model.setValueAt("0", rowCount, 1); rowCount++; } this.jResultsTable.setModel(model); this.dirname = dir.getName(); } }
From source file:com.etas.jenkins.plugins.VersionPatcher.PatchFilesTask.java
public Boolean call() throws IOException { try {//from w ww .j av a 2s . co m File searchDir = new File(searchPath); Collection<File> resourceFiles = FileUtils.listFiles(searchDir, new RegexFileFilter(fileExtension), DirectoryFileFilter.DIRECTORY); if ((resourceFiles.size() <= 0)) { listener.getLogger().println("No files to process."); return true; } String fVersion = fileVersion.replace(".", ","); String prVersion = productVersion.replace(".", ","); for (File rcfile : resourceFiles) { String detectedEncoding = FileEncodingDetector.getFileEncoding(rcfile); String content = FileUtils.readFileToString(rcfile, detectedEncoding); if (rcfile.getName().endsWith(".rc")) { content = content.replaceAll("(.*?FILEVERSION.*.)", " FILEVERSION " + fVersion); content = content.replaceAll("\"FileVersion.*.", "\"FileVersion\", \"" + fileVersion + "\""); content = content.replaceAll("(.*?PRODUCTVERSION.*.)", " PRODUCTVERSION " + prVersion); content = content.replaceAll("\"ProductVersion.*.", "\"ProductVersion\", \"" + productVersion + "\""); content = content.replaceAll("\"LegalCopyright.*.", "\"LegalCopyright\", \"" + copyrightString + "\""); listener.getLogger().println(String.format("Updating resource file: '%s'. Encoding: %s", rcfile.getAbsolutePath(), detectedEncoding)); } else if (rcfile.getName().equals("AssemblyInfo.cs")) { content = content.replaceAll("AssemblyFileVersion.*.", "AssemblyFileVersion(\"" + fileVersion + "\")]"); content = content.replaceAll("AssemblyVersion.*.", "AssemblyVersion(\"" + productVersion + "\")]"); content = content.replaceAll("AssemblyCopyright.*.", "AssemblyCopyright(\"" + copyrightString + "\")]"); listener.getLogger().println(String.format("Updating AssemblyInfo.cs file: '%s'. Encoding: %s", rcfile.getAbsolutePath(), detectedEncoding)); } else if (rcfile.getName().equals("AssemblyInfo.cpp")) { content = content.replaceAll("AssemblyFileVersionAttribute.*.", "AssemblyFileVersionAttribute(\"" + fileVersion + "\")]"); content = content.replaceAll("AssemblyVersionAttribute.*.", "AssemblyVersionAttribute(\"" + productVersion + "\")]"); content = content.replaceAll("AssemblyCopyrightAttribute.*.", "AssemblyCopyrightAttribute(\"" + copyrightString + "\")]"); listener.getLogger().println(String.format("Updating AssemblyInfo.cpp file: '%s'. Encoding: %s", rcfile.getAbsolutePath(), detectedEncoding)); } else { listener.getLogger() .println(String.format("Error: Invalid file: '%s'", rcfile.getAbsolutePath())); } FileUtils.writeStringToFile(rcfile, content, detectedEncoding); } } catch (Exception e) { listener.getLogger().println(e.getMessage()); e.printStackTrace(listener.getLogger()); return false; } return true; }
From source file:jhc.redsniff.generation.PackageScanningGenerator.java
private Collection<String> classesInPackage(String package_name_prefix) { File packageDir = new File( sourceDir.getAbsolutePath() + "\\" + package_name_prefix.replaceAll("\\.", "\\\\")); Set<String> classNames = new HashSet<String>(); for (File classFile : FileUtils.listFiles(packageDir, FileFilterUtils.suffixFileFilter(".java"), TrueFileFilter.INSTANCE))/*from w ww . ja v a 2 s . com*/ classNames.add(classFile.getAbsolutePath().replace(sourceDir.getAbsolutePath() + "\\", "") .replace(".java", "").replaceAll("\\\\", ".")); //classNames.remove(o) return classNames; }