List of usage examples for org.apache.commons.io FileUtils convertFileCollectionToFileArray
public static File[] convertFileCollectionToFileArray(Collection files)
From source file:kr.co.leem.system.FileSystemUtils.java
/** * ? ?? ./*from w w w.j a v a 2 s. co m*/ * * @param dirPath . * @param name . * @param fileNameSearch . * @return ? ?. * @see FileUtils#listFiles(File, IOFileFilter, IOFileFilter) * @see FileFilterUtils#nameFileFilter(String) * @see FileFilterUtils#prefixFileFilter(String) * @see FileFilterUtils#suffixFileFilter(String) */ public static File[] getFileList(final String dirPath, final String name, final searchFileName fileNameSearch) { return processIO(new IOCallback<File[]>() { public File[] doInProcessIO() throws IOException, NullPointerException { IOFileFilter fileFilter; switch (fileNameSearch) { case FULL_MATCH: fileFilter = FileFilterUtils.nameFileFilter(name); break; case PREFIX: fileFilter = FileFilterUtils.prefixFileFilter(name); break; case SUFFIX: fileFilter = FileFilterUtils.suffixFileFilter(name); break; default: fileFilter = FileFilterUtils.nameFileFilter(name); break; } Collection<File> files = FileUtils.listFiles(new File(dirPath), fileFilter, DirectoryFileFilter.DIRECTORY); return FileUtils.convertFileCollectionToFileArray(files); } }); }
From source file:org.javascool.compiler.Compiler.java
/** * Initialise le compilateur avec un rpertoire et une liste de fichiers * * @param directory Le rpertoire o on doit travailler * @param javas Les fichiers compiler *///from ww w. j av a2 s. co m public Compiler(File directory, File... javas) { assertDirectoryExists(directory); srcDirectory = directory; ArrayList<File> sources = new ArrayList<File>(javas.length); for (File javaSource : javas) { if (!javaSource.isAbsolute()) javaSource = new File(directory, javaSource.getPath()); assertFileExists(javaSource); sources.add(javaSource); } filesToCompile = FileUtils.convertFileCollectionToFileArray(sources); }
From source file:org.javascool.compiler.Compiler.java
/** * Initialize un compilateur pour compiler tous les java d'un dossier. * * @param directory Le rpertoire o on doit travailler */// w ww. j a va 2s . c om public Compiler(File directory) { assertDirectoryExists(directory); srcDirectory = directory; filesToCompile = FileUtils .convertFileCollectionToFileArray(FileUtils.listFiles(directory, new String[] { "java" }, true)); }
From source file:org.nanoko.playframework.mojo.Play2PackageMojo.java
private File moveApplicationPackageToTarget() throws MojoExecutionException { File target = getBuildDirectory(); File[] files = FileUtils.convertFileCollectionToFileArray( FileUtils.listFiles(target, new PackageFileFilter(), new PrefixFileFilter("scala-"))); File mainJar = null;/* w w w. j a va 2 s . c o m*/ for (File file : files) { // We need to distinguish which file is the main artifacts. // We filter out -sources and -javadoc files. if (!file.getName().endsWith("-javadoc.jar") && !file.getName().endsWith("-sources.jar")) { mainJar = file; } } if (mainJar == null) { throw new MojoExecutionException("Cannot find packaged file"); } try { if (StringUtils.isBlank(classifier)) { File out = new File(target, project.getBuild().getFinalName() + ".jar"); getLog().info("Copying " + files[0].getName() + " to " + out.getName()); FileUtils.copyFile(mainJar, out); return out; } else { File out = new File(target, project.getBuild().getFinalName() + "-" + classifier + ".jar"); getLog().info("Copying " + files[0].getName() + " to " + out.getName()); FileUtils.copyFile(mainJar, out); return out; } } catch (IOException e) { throw new MojoExecutionException( "Cannot copy package file " + files[0].getAbsolutePath() + " to " + target.getAbsolutePath()); } }
From source file:org.nanoko.playframework.mojo.Play2PackageMojo.java
private void moveJavadocAndSourcesArtifactsToTarget() throws MojoExecutionException { File sourceJar = null;/*from w ww . j av a 2 s.c om*/ File javadocJar = null; File target = getBuildDirectory(); File[] files = FileUtils.convertFileCollectionToFileArray( FileUtils.listFiles(target, new PackageFileFilter(), new PrefixFileFilter("scala-"))); for (File file : files) { // We need to select the right file. if (file.getName().endsWith("-sources.jar")) { sourceJar = file; } else if (file.getName().endsWith("-javadoc.jar")) { javadocJar = file; } } try { if (sourceJar != null) { getLog().info("Artifact containing sources found - copying to target"); File out = new File(target, project.getBuild().getFinalName() + "-sources.jar"); FileUtils.copyFile(sourceJar, out); } if (javadocJar != null) { getLog().info("Artifact containing javadoc found - copying to target"); File out = new File(target, project.getBuild().getFinalName() + "-javadoc.jar"); FileUtils.copyFile(javadocJar, out); } } catch (IOException e) { throw new MojoExecutionException("Can't copy the javadoc and sources file to the target folder", e); } }
From source file:org.nuxeo.ecm.automation.core.operations.blob.BlobToFileTest.java
@Test public void testExportBlobToFS() throws Exception { OperationContext ctx = buildCtx(session); targetDirectory = createAllowedTargetDirectory(); Map<String, Object> params = buildParams(targetDirectory); Blob outputBlob = (Blob) automationService.run(ctx, BlobToFile.ID, params); assertNotNull(outputBlob);//w w w. jav a 2s .c om assertEquals(pdfFile, outputBlob.getFile()); File[] directoryContent = FileUtils .convertFileCollectionToFileArray(FileUtils.listFiles(targetDirectory, null, false)); assertEquals(1, directoryContent.length); assertEquals(new File(targetDirectory.getAbsolutePath(), PDF_NAME), directoryContent[0]); }
From source file:org.openvpms.tools.data.loader.StaxArchetypeDataLoader.java
/** * Process all the files in the directory * * @param dir the directory//www. j av a 2 s . com * @param loader the loader * @throws FileNotFoundException if the file cannot be found * @throws XMLStreamException if the file cannot be parsed */ private void processDir(File dir, DataLoader loader) throws XMLStreamException, FileNotFoundException { String[] extensions = { EXTENSION }; Collection collection = FileUtils.listFiles(dir, extensions, false); File[] files = FileUtils.convertFileCollectionToFileArray(collection); Arrays.sort(files); for (int i = 0, n = files.length; i < n; i++) { File file = files[i]; processFile(file, loader); loader.flush(); } }
From source file:org.starnub.utilities.file.utility.FileManager.java
private File[] scan() { Collection<File> files = FileUtils.listFiles(DIRECTORY, EXTENSIONS, false); return FileUtils.convertFileCollectionToFileArray(files); }
From source file:starnubserver.plugins.PluginManager.java
private void pluginScan(boolean isUpdating) throws MalformedURLException { UNLOADED_PLUGINS.clear();/*from w w w. j a v a 2s . c om*/ File[] pluginFiles = FileUtils.convertFileCollectionToFileArray( FileUtils.listFiles(new File(pluginDirString), new String[] { "jar" }, false)); for (File pluginFile : pluginFiles) { URL pluginUrl = pluginFile.toURI().toURL(); URLClassLoader classLoader = new URLClassLoader(new URL[] { pluginUrl }, StarNub.class.getClassLoader()); StarNubYamlWrapper data = new StarNubYamlWrapper("StarNub", "StarNub - PluginLoader", classLoader.getResourceAsStream("plugin.yml"), ""); String pluginName = (String) data.getValue("name"); double version = (double) data.getNestedValue("details", "version"); if (UNLOADED_PLUGINS.containsKey(pluginName)) { UnloadedPlugin unloadedPlugin = UNLOADED_PLUGINS.get(pluginName); double storedVersion = unloadedPlugin.getPLUGIN_VERSION(); if (storedVersion < version) { String removeFileRecommend = unloadedPlugin.getPLUGIN_FILE().toString(); UNLOADED_PLUGINS.remove(pluginName); if (!isUpdating) { StarNub.getLogger().cErrPrint("StarNub", "You have multiple " + pluginName + " plugins, some are older, we recommend you remove the older file named " + removeFileRecommend + "."); } } } UNLOADED_PLUGINS.putIfAbsent(pluginName, new UnloadedPlugin(pluginName, version, pluginUrl, classLoader, data)); } }