List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.facelets.ValidatingFaceletsParserExecutor.java
@SuppressWarnings("unchecked") private Collection<File> findTaglibFiles() { File webInfDir = new File(webappRoot, "WEB-INF"); if (!webInfDir.isDirectory()) { throw new IllegalArgumentException("The provided path seems not to be a web application root " + "folder - there is no " + webInfDir); }//from w w w .j a v a 2s .c o m Collection taglibs = FileUtils.listFiles(webInfDir, new String[] { "taglib.xml" }, true); LOG.info("Local taglibs found under webroot/WEB-INF: " + taglibs); return taglibs; }
From source file:com.dragansah.filebrowser.components.FileBrowser.java
public List<FileModel> getFiles() { List<FileModel> files = new ArrayList<FileModel>(); File[] subDirs = currentDirectory.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); if (!topDirectory.getPath().equals(currentDirectory.getPath())) files.add(FileModel.getPreviousDirectory(currentDirectory)); for (File f : subDirs) files.add(FileModel.fromFile(f)); for (File f : FileUtils.listFiles(currentDirectory, null, false)) { files.add(FileModel.fromFile(f)); // FileSystemView view = FileSystemView.getFileSystemView(); }/* w w w . jav a2 s . c o m*/ return files; }
From source file:com.tera.common.vcontext.service.ContextConfigurationParser.java
/** * @param bundle com.tera.common.vcontext bundle * @param directory top directory with filesystem data *///from w w w .j av a 2s . com public static final void parseConfigurationDirectory(Bundle bundle, String directory) { Unmarshaller un = JaxbUtil.create(VContextTemplate.class, bundle.getResource("vcontext.xsd")); File file = new File(directory); if (file.isDirectory()) { File[] contextDirs = file.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); log.info("Found {} filesystem directories", contextDirs.length); for (File dir : contextDirs) { Collection<File> contextFiles = FileUtils.listFiles(dir, new NameFileFilter("vcontext.xml"), null); for (File contextFile : contextFiles) { try { VContextTemplate context = (VContextTemplate) un .unmarshal(contextFile.toURI().toURL().openStream()); parseRealConfiguration(dir.getAbsolutePath(), context); } catch (Exception e) { log.error("Exception when parsing context resource {}", contextFile.getName(), e); } } } } else { log.warn("Specified context directory doesn't exists {}", directory); } }
From source file:com.simpligility.maven.provisioner.MavenRepositoryHelper.java
public void deployToRemote(String targetUrl, String username, String password) { // Using commons-io, if performance or so is a problem it might be worth looking at the Java 8 streams API // e.g. http://blog.jooq.org/2014/01/24/java-8-friday-goodies-the-new-new-io-apis/ // not yet though.. Collection<File> subDirectories = FileUtils.listFilesAndDirs(repositoryPath, (IOFileFilter) DirectoryFileFilter.DIRECTORY, TrueFileFilter.INSTANCE); Collection<File> leafDirectories = new ArrayList<File>(); for (File subDirectory : subDirectories) { if (isLeafVersionDirectory(subDirectory)) { leafDirectories.add(subDirectory); }//from ww w . ja v a 2 s .c o m } for (File leafDirectory : leafDirectories) { String leafAbsolutePath = leafDirectory.getAbsoluteFile().toString(); int repoAbsolutePathLength = repositoryPath.getAbsoluteFile().toString().length(); String leafRepoPath = leafAbsolutePath.substring(repoAbsolutePathLength + 1, leafAbsolutePath.length()); Gav gav = GavUtil.getGavFromRepositoryPath(leafRepoPath); // only interested in files using the artifactId-version* pattern // don't bother with .sha1 files IOFileFilter fileFilter = new AndFileFilter( new WildcardFileFilter(gav.getArtifactId() + "-" + gav.getVersion() + "*"), new NotFileFilter(new SuffixFileFilter("sha1"))); Collection<File> artifacts = FileUtils.listFiles(leafDirectory, fileFilter, null); Authentication auth = new AuthenticationBuilder().addUsername(username).addPassword(password).build(); RemoteRepository distRepo = new RemoteRepository.Builder("repositoryIdentifier", "default", targetUrl) .setAuthentication(auth).build(); DeployRequest deployRequest = new DeployRequest(); deployRequest.setRepository(distRepo); for (File file : artifacts) { String extension; if (file.getName().endsWith("tar.gz")) { extension = "tar.gz"; } else { extension = FilenameUtils.getExtension(file.getName()); } String baseFileName = gav.getFilenameStart() + "." + extension; String fileName = file.getName(); String g = gav.getGroupdId(); String a = gav.getArtifactId(); String v = gav.getVersion(); Artifact artifact = null; if (gav.getPomFilename().equals(fileName)) { artifact = new DefaultArtifact(g, a, "pom", v); } else if (gav.getJarFilename().equals(fileName)) { artifact = new DefaultArtifact(g, a, "jar", v); } else if (gav.getSourceFilename().equals(fileName)) { artifact = new DefaultArtifact(g, a, "sources", "jar", v); } else if (gav.getJavadocFilename().equals(fileName)) { artifact = new DefaultArtifact(g, a, "javadoc", "jar", v); } else if (baseFileName.equals(fileName)) { artifact = new DefaultArtifact(g, a, extension, v); } else { String classifier = file.getName().substring(gav.getFilenameStart().length() + 1, file.getName().length() - ("." + extension).length()); artifact = new DefaultArtifact(g, a, classifier, extension, v); } if (artifact != null) { artifact = artifact.setFile(file); deployRequest.addArtifact(artifact); } } try { system.deploy(session, deployRequest); } catch (Exception e) { logger.info("Deployment failed with " + e.getMessage() + ", artifact might be deployed already."); } } }
From source file:eumetsat.pn.solr.SolrFeeder.java
@Override protected void indexDirContent(Path aSrcDir) { log.info("Indexing dir content {}", aSrcDir); JSONParser parser = new JSONParser(); YamlNode endpointConfig = this.config.get("endpoint"); String collection = endpointConfig.get("collection").asTextValue(); SolrServer solr;// www .j a va 2 s . c o m if (this.server != null) { solr = server; log.info("Using embedded SolrServer: {}", solr); } else { log.info("Endpoint configuration: {}", endpointConfig); String solrEndpoint = endpointConfig.get("url").asTextValue(); solr = new ConcurrentUpdateSolrServer(solrEndpoint + "/" + collection, 10, 1); // CloudSolrServer solr = new CloudSolrServer(solrEndpoint); // solr.setDefaultCollection(collection); log.info("Using HTTP SolrServer: {}", solr); } SolrPingResponse ping; try { ping = solr.ping(); log.debug("Pinged Solr server: {}", ping); } catch (SolrServerException | IOException | RemoteSolrException e) { log.error("Could not ping Solr server", e); } // Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", endpointConfig.get("cluster.name").asTextValue()).build(); int cpt = 0; Collection<File> inputFiles = FileUtils.listFiles(aSrcDir.toFile(), new String[] { "json" }, false); log.info("Indexing {} files...", inputFiles.size()); for (File file : inputFiles) { try { String jsonStr = FileUtils.readFileToString(file); JSONObject jsObj = (JSONObject) parser.parse(jsonStr); try { SolrInputDocument input = createInputDoc(jsObj); log.debug("Adding {} to collection {}", file.getName(), collection); log.trace("Full json of {}: {}", file.getName(), input); solr.add(input); cpt++; } catch (RuntimeException e) { log.error("Error processing input document {}: {}, {}", file, e, e.getMessage()); } if (cpt % 42 == 0) { // periodically flush log.info("Commiting to server, document count is {}", cpt); UpdateResponse response = solr.commit(); log.info("Response status: {} (time: {}): {}", response.getStatus(), response.getElapsedTime(), response.toString()); } } catch (IOException | ParseException | SolrServerException e) { log.error("Error comitting document based on file {}", file, e); } } try { solr.commit(); } catch (IOException | SolrServerException e) { log.error("Error comitting document", e); } solr.shutdown(); log.info("Indexed {} of {} files.", cpt, inputFiles.size()); }
From source file:android.databinding.compilationTest.BaseCompilationTest.java
protected void copyResourceDirectory(String name, String targetPath) throws URISyntaxException, IOException { URL dir = getClass().getResource(name); assertNotNull(dir);//w ww.j a v a 2 s. co m assertEquals("file", dir.getProtocol()); File folder = new File(dir.toURI()); assertTrue(folder.isDirectory()); File target = new File(testFolder, targetPath); int len = folder.getAbsolutePath().length() + 1; for (File item : FileUtils.listFiles(folder, null, true)) { if (item.getAbsolutePath().equals(folder.getAbsolutePath())) { continue; } String resourcePath = item.getAbsolutePath().substring(len); copyResourceTo(name + "/" + resourcePath, new File(target, resourcePath)); } }
From source file:com.feedzai.fos.impl.weka.WekaManagerTest.java
@After public void cleanup() { Collection<File> files = FileUtils.listFiles(new File("target/test-classes/models/threadsafe"), new String[] { WekaManagerConfig.HEADER_EXTENSION }, false); for (File file : files) { if (!file.getName().startsWith("test")) { file.delete();/*from w w w .j a v a2 s. c o m*/ } } if (wekaManager != null) { try { wekaManager.close(); } catch (FOSException e) { } } }
From source file:de.extra.client.plugins.dataplugin.FileDataPluginTest.java
/** * Test method for//from www.ja v a 2 s .c o m * {@link de.extra.client.plugins.dataplugin.FileDataPlugin#getData()}. */ @Test public final void testGetData() { int counter = 0; while (fileDataPlugin.hasMoreData()) { final IInputDataContainer iInputDataContainer = fileDataPlugin.getData(); Assert.assertFalse(iInputDataContainer.isContentEmpty()); Assert.assertTrue(iInputDataContainer.isImplementationOf(ContentInputDataContainer.class)); Assert.assertTrue("iInputDataContainer size grer als Limit", iInputDataContainer.getContentSize() <= inputDataLimit); counter = counter + iInputDataContainer.getContentSize(); } final Collection<File> listFiles = FileUtils.listFiles(inputDirectory, TrueFileFilter.INSTANCE, null); Assert.assertEquals("Number of messages does not match", listFiles.size(), counter); }
From source file:com.openkm.servlet.admin.LogCatServlet.java
/** * List logs/*from w w w .j a v a 2 s . c om*/ */ private void list(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("list({}, {})", request, response); ServletContext sc = getServletContext(); sc.setAttribute("files", FileUtils.listFiles(logFolder, null, false)); sc.getRequestDispatcher("/admin/logcat.jsp").forward(request, response); // Activity log UserActivity.log(request.getRemoteUser(), "ADMIN_LOGCAT_LIST", null, null, logFolder.getPath()); log.debug("list: void"); }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
protected void validateConfigs(File samplesDir, String configFileWildcard, boolean checkStreams, List<String> skipFiles) throws Exception { Collection<File> sampleConfigurations = FileUtils.listFiles(samplesDir, FileFilterUtils.asFileFilter( (FilenameFilter) new WildcardFileFilter(configFileWildcard, IOCase.INSENSITIVE)), TrueFileFilter.INSTANCE);/*from ww w.j a va 2 s. c om*/ Collection<File> sampleConfigurationsFiltered = new ArrayList<>(sampleConfigurations); if (CollectionUtils.isNotEmpty(skipFiles)) { for (File sampleConfiguration : sampleConfigurations) { for (String skipFile : skipFiles) { if (sampleConfiguration.getAbsolutePath().contains(skipFile)) sampleConfigurationsFiltered.remove(sampleConfiguration); } } } for (File sampleConfiguration : sampleConfigurationsFiltered) { System.out.println("Reading configuration file: " + sampleConfiguration.getAbsolutePath()); // NON-NLS Reader testReader = new FileReader(sampleConfiguration); SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser parser = parserFactory.newSAXParser(); ConfigParserHandler hndlr = new ConfigParserHandler(); parser.parse(new InputSource(testReader), hndlr); assertNotNull("Parsed streams config data is null", hndlr.getStreamsConfigData()); boolean parseable = true; if (checkStreams) { assertTrue("No configured streams", hndlr.getStreamsConfigData().isStreamsAvailable()); parseable = false; for (TNTInputStream<?, ?> s : hndlr.getStreamsConfigData().getStreams()) { if (s instanceof TNTParseableInputStream) { parseable = true; break; } } } if (parseable) { assertTrue("No configured parsers", hndlr.getStreamsConfigData().isParsersAvailable()); } Utils.close(testReader); } }