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.music.Generator.java
@PostConstruct public void init() throws MidiUnavailableException, IOException, InvalidMidiDataException { //TODO http://marsyas.info/ when input signal processing is needed semaphore = new Semaphore(maxConcurrentGenerations); manipulators.add(new MetreConfigurer()); manipulators.add(new PartConfigurer()); manipulators.add(new ScaleConfigurer()); manipulators.add(new MainPartGenerator()); manipulators.add(new AccompanimentPartGenerator()); manipulators.add(new Arpeggiator()); manipulators.add(new PercussionGenerator()); manipulators.add(new SimpleBeatGenerator()); manipulators.add(new BassPartGenerator()); manipulators.add(new DroneGenerator()); manipulators.add(new EffectsGenerator()); manipulators.add(new PadsGenerator()); manipulators.add(new TimpaniPartGenerator()); manipulators.add(new TitleGenerator()); try {/* w w w . j a va 2 s. c o m*/ Collection<File> files = FileUtils.listFiles(new File(configLocation + "/soundbanks/"), new String[] { "sf2" }, false); for (File file : files) { InputStream is = new BufferedInputStream(new FileInputStream(file)); soundbanks.add(MidiSystem.getSoundbank(is)); } } catch (IOException ex) { logger.warn("Problem loading soundbank: " + ex.getMessage()); // ignore } //initJMusicSynthesizer(); }
From source file:massbank.svn.OpenDataUpdater.java
/** * //from w w w . ja v a 2s . c om */ private boolean isFileUpdating() { File file = new File(srcRecordPath); String[] extensions = { "txt" }; List<File> fileList1 = (List<File>) FileUtils.listFiles(file, extensions, false); if (fileList1 == null) { return false; } try { sleep(30 * TIME_SEC); } catch (Exception e) { } List<File> fileList2 = (List<File>) FileUtils.listFiles(file, extensions, false); if (fileList2 == null) { return false; } FileDifference diff = new FileDifference(fileList1, fileList2); String[] addFilePaths = diff.getAddFilePaths(); String[] delFileNames = diff.getDeleteFileNames(); if (addFilePaths.length == 0 || delFileNames.length == 0) { return false; } return true; }
From source file:com.github.seqware.queryengine.impl.TmpFileStorage.java
/** {@inheritDoc} */ @Override// w w w. ja v a 2 s. c om public Atom deserializeTargetToAtom(SGID sgid) { // let's just clone everything on store to simulate hbase try { if (sgid == null) { return null; } //FileTypePair target = map.get(sgid); String suffix = NonPersistentStorage.createKey(sgid); String regex = "[a-zA-Z_0-9\\.]+~" + suffix; Collection<File> listFiles = FileUtils.listFiles(tempDir, new RegexFileFilter(regex), null); assert (listFiles.size() == 1); Atom suspect = handleFileWithoutClass(listFiles.iterator().next()); if (suspect != null) { return suspect; } return null; } catch (IOException ex) { Logger.getLogger(TmpFileStorage.class.getName()).fatal("Failure to deserialize", ex); } throw new RuntimeException("Serious problem with file storage"); }
From source file:com.aionlightning.commons.scripting.impl.ScriptContextImpl.java
/** * {@inheritDoc}/*from w ww . j a v a 2 s .com*/ */ @Override public synchronized void init() { if (compilationResult != null) { log.error("Init request on initialized ScriptContext"); return; } ScriptCompiler scriptCompiler = instantiateCompiler(); Collection<File> files = FileUtils.listFiles(root, scriptCompiler.getSupportedFileTypes(), true); if (parentScriptContext != null) { scriptCompiler.setParentClassLoader(parentScriptContext.getCompilationResult().getClassLoader()); } scriptCompiler.setLibraires(libraries); compilationResult = scriptCompiler.compile(files); getClassListener().postLoad(compilationResult.getCompiledClasses()); if (childScriptContexts != null) { for (ScriptContext context : childScriptContexts) { context.init(); } } }
From source file:com.thoughtworks.go.server.initializers.PluginsInitializerTest.java
@Test public void shouldNotReplacePluginsIfTheSameVersionWasAlreadyExploded() throws IOException { String version = "13.3.0(17222-4c7fabcb9c9e9c)"; File versionFile = temporaryFolder.newFile("go-plugins/version.txt"); FileUtils.writeStringToFile(versionFile, version, UTF_8); pluginsInitializer.initialize();/*from ww w . j a va 2s .c o m*/ Collection collection = FileUtils.listFiles(goPluginsDir, null, true); assertThat(collection.size(), is(1)); assertThat(collection.contains(versionFile), is(true)); }
From source file:averroes.JarFile.java
/** * Add the generated AverroesLibraryClass file to the Jar file. * //from www .jav a 2 s . c o m * @throws IOException * @throws URISyntaxException */ public void addAverroesLibraryClassFile() throws IOException, URISyntaxException { File dir = Paths.libraryClassesOutputDirectory(); File placeholderJar = Paths.placeholderLibraryJarFile(); File averroesLibraryClassJar = Paths.averroesLibraryClassJarFile(); File file = FileUtils.listFiles(dir, new String[] { "class" }, true).stream() .filter(f -> relativize(dir, f).equals(Names.AVERROES_LIBRARY_CLASS_BC_SIG + ".class")) .collect(Collectors.toList()).get(0); String className = relativize(dir, file); // Add the class file to the separately crafted JAR file. if (file.isFile()) { add(dir, file); } else { throw new IllegalStateException("cannot find " + Names.AVERROES_LIBRARY_CLASS + System.getProperty("line.separator") + "Invalid path given: " + fileName); } close(); // Set BCEL's repository class path. SyntheticRepository rep = SyntheticRepository.getInstance(new ClassPath(averroesLibraryClassJar + File.pathSeparator + placeholderJar + File.pathSeparator + Paths.organizedApplicationJarFile())); Repository.setRepository(rep); // Now add the class files (including ones from placeholder JAR) to the // BCEL repository. ClassParser parser = new ClassParser(averroesLibraryClassJar.getPath(), className); JavaClass cls = parser.parse(); bcelClasses.add(cls); // Now we need to add all the BCEL classes (including ones from previous // placeholder JAR to force BCEL to load // those crafted files when it looks them up bcelClasses.forEach(c -> Repository.getRepository().storeClass(c)); // Now verify all the generated class files verify(); }
From source file:adalid.util.meta.sql.MetaFolderSql.java
private boolean readFiles() { // Path base = metaFolderPath; Path base = metaFolderPath.getParent(); Collection<File> list = FileUtils.listFiles(metaFolder, fileFilter(), dirFilter()); FileWrapper wrapper;/*from ww w. jav a 2 s .c om*/ long bytes, lines; String type; for (File file : list) { wrapper = new FileWrapper(file); wrapper.read(); bytes = wrapper.getBytes(); lines = wrapper.getLines(); if (wrapper.isNotEmpty()) { files.put(wrapper.getPath(), wrapper); type = wrapper.getType(); updateFileTypes(type); updateFolders(wrapper); } readingWarnings += wrapper.getReadingWarnings(); readingErrors += wrapper.getReadingErrors(); logger.debug("file=" + wrapper.getRelativePath(base) + ", " + wrapper.getCharset() + ", " + bytes + ", " + lines); } updateFolders(); return true; }
From source file:gov.nasa.ensemble.common.ui.FileSystemExportWizardPage.java
protected void createDirectoryGroup(Composite parent) { if (this.dir.exists() && this.dir.isDirectory() && this.dir.canRead()) { listViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); listViewer.getTable().setLayoutData(data); listViewer.getTable().setFont(parent.getFont()); listViewer.setContentProvider(new IStructuredContentProvider() { @Override/*from ww w .ja v a 2s . com*/ public Object[] getElements(Object inputElement) { return FileUtils.listFiles(FileSystemExportWizardPage.this.dir, null, false).toArray(); } @Override public void dispose() { /* empty */ } @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { /* empty */ } }); listViewer.setLabelProvider(new ILabelProvider() { @Override public String getText(Object element) { if (element instanceof File) return ((File) element).getName(); return null; } @Override public boolean isLabelProperty(Object element, String property) { return true; } @Override public Image getImage(Object element) { return null; } @Override public void addListener(ILabelProviderListener listener) { /* empty */ } @Override public void removeListener(ILabelProviderListener listener) { /* empty */ } @Override public void dispose() { /* empty */ } }); listViewer.setInput(this.dir); } else { Logger.getLogger(getClass()).error("Invalid source directory: " + this.dirName); setErrorMessage("Invalid source directory: " + this.dirName); } }
From source file:com.przyjaznyplan.utils.CsvConverter.java
private void ifImageGetIt(String value, ContentValues sqlValues) { if (value != null && (value.endsWith(JPG_EXT) || value.endsWith(JPEG_EXT) || value.endsWith(PNG_EXT))) { Collection files = FileUtils.listFiles(new File(rootFolder), new NameFileFilter(value), TrueFileFilter.INSTANCE); Iterator<File> iterator = files.iterator(); if (iterator.hasNext()) { File f = iterator.next(); sqlValues.put(Czynnosc.IMAGE, f.getAbsolutePath()); }/* w ww. j av a2s . c o m*/ } }
From source file:com.temenos.interaction.loader.detector.SpringBasedLoaderAction.java
@Override public void execute(FileEvent<File> dirEvent) { LOGGER.debug("Creation of new Spring ApplicationContext based CommandController triggerred by change in", dirEvent.getResource().getAbsolutePath()); Collection<File> jars = FileUtils.listFiles(dirEvent.getResource(), new String[] { "jar" }, true); Set<URL> urls = new HashSet(); for (File f : jars) { try {//from ww w .ja v a 2s. c o m LOGGER.trace("Adding {} to list of URLs to create ApplicationContext from", f.toURI().toURL()); urls.add(f.toURI().toURL()); } catch (MalformedURLException ex) { // kindly ignore and log } } Reflections reflectionHelper = new Reflections( new ConfigurationBuilder().addClassLoader(classloaderFactory.getForObject(dirEvent)) .addScanners(new ResourcesScanner()).addUrls(urls)); Set<String> resources = new HashSet(); for (String locationPattern : configLocationsPatterns) { String regex = convertWildcardToRegex(locationPattern); resources.addAll(reflectionHelper.getResources(Pattern.compile(regex))); } if (!resources.isEmpty()) { // if resources are empty just clean up the previous ApplicationContext and leave! LOGGER.debug("Detected potential Spring config files to load"); ClassPathXmlApplicationContext context; if (parentContext != null) { context = new ClassPathXmlApplicationContext(parentContext); } else { context = new ClassPathXmlApplicationContext(); } context.setConfigLocations(configLocationsPatterns.toArray(new String[] {})); ClassLoader childClassLoader = classloaderFactory.getForObject(dirEvent); context.setClassLoader(childClassLoader); context.refresh(); CommandController cc = null; try { cc = context.getBean(commandControllerBeanName, CommandController.class); LOGGER.debug("Detected pre-configured CommandController in added config files"); } catch (BeansException ex) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("No detected pre-configured CommandController in added config files.", ex); } Map<String, InteractionCommand> commands = context.getBeansOfType(InteractionCommand.class); if (!commands.isEmpty()) { LOGGER.debug("Adding new commands"); SpringContextBasedInteractionCommandController scbcc = new SpringContextBasedInteractionCommandController(); scbcc.setApplicationContext(context); cc = scbcc; } else { LOGGER.debug("No commands detected to be added"); } } if (parentChainingCommandController != null) { List<CommandController> newCommandControllers = new ArrayList<CommandController>( parentChainingCommandController.getCommandControllers()); // "unload" the previously loaded CommandController if (previouslyAddedCommandController != null) { LOGGER.debug("Removing previously added instance of CommandController"); newCommandControllers.remove(previouslyAddedCommandController); } // if there is a new CommandController on the Spring file, add it on top of the chain if (cc != null) { LOGGER.debug("Adding newly created CommandController to ChainingCommandController"); newCommandControllers.add(0, cc); parentChainingCommandController.setCommandControllers(newCommandControllers); previouslyAddedCommandController = cc; } else { previouslyAddedCommandController = null; } } else { LOGGER.debug( "No ChainingCommandController set to add newly created CommandController to - skipping action"); } if (previousAppCtx != null) { if (previousAppCtx instanceof Closeable) { try { ((Closeable) previousAppCtx).close(); } catch (Exception ex) { LOGGER.error("Error closing the ApplicationContext.", ex); } } previousAppCtx = context; } } else { LOGGER.debug("No Spring config files detected in the JARs scanned"); } }