List of usage examples for org.apache.commons.io.filefilter SuffixFileFilter SuffixFileFilter
public SuffixFileFilter(List suffixes)
From source file:org.ut.medsavant.annotation.format.MedSavantAnnotationFormatter.java
/** * @param args the command line arguments *//*from ww w .j a v a 2s .c o m*/ public static void main(String[] args) throws Exception { String rootpath = "./"; for (String child : new File(rootpath) .list(new SuffixFileFilter(new String[] { idf_ext, tsv_ext, txt_ext }))) { System.out.println("Processing " + child); try { processFile(new File(rootpath + child)); } catch (Exception e) { System.err.println("Error processing " + child); e.printStackTrace(); continue; } } }
From source file:org.walkmod.util.FileResource.java
@Override public Iterator<File> iterator() { String fileNormalized = FilenameUtils.normalize(file.getAbsolutePath(), true); if (includes != null) { for (int i = 0; i < includes.length; i++) { if (!includes[i].startsWith(fileNormalized)) { includes[i] = fileNormalized + "/" + includes[i]; }/*from ww w .j a va 2s .c o m*/ if (includes[i].endsWith("**")) { includes[i] = includes[i].substring(0, includes[i].length() - 3); } } } if (excludes != null) { for (int i = 0; i < excludes.length; i++) { if (!excludes[i].startsWith(fileNormalized)) { excludes[i] = fileNormalized + "/" + excludes[i]; } if (excludes[i].endsWith("**")) { excludes[i] = excludes[i].substring(0, excludes[i].length() - 3); } } } if (file.isDirectory()) { IOFileFilter filter = null; IOFileFilter directoryFilter = TrueFileFilter.INSTANCE; if (excludes != null || includes != null) { directoryFilter = new IOFileFilter() { @Override public boolean accept(File dir, String name) { boolean excludesEval = false; boolean includesEval = false; String aux = FilenameUtils.normalize(name, true); if (excludes != null) { for (int i = 0; i < excludes.length && !excludesEval; i++) { excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || dir.getAbsolutePath().startsWith(excludes[i])); } } if (includes != null) { for (int i = 0; i < includes.length && !includesEval; i++) { includesEval = matches(aux, includes[i]); } } else { includesEval = true; } return (includesEval && !excludesEval) || (includes == null && excludes == null); } @Override public boolean accept(File file) { boolean excludesEval = false; boolean includesEval = false; String aux = FilenameUtils.normalize(file.getAbsolutePath(), true); if (excludes != null) { for (int i = 0; i < excludes.length && !excludesEval; i++) { excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || file.getParentFile().getAbsolutePath().startsWith(excludes[i])); } } if (includes != null) { for (int i = 0; i < includes.length && !includesEval; i++) { includesEval = matches(aux, includes[i]); } } else { includesEval = true; } boolean result = (includesEval && !excludesEval) || (includes == null && excludes == null); return result; } }; if (extensions == null) { filter = directoryFilter; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } } else { if (extensions == null) { filter = TrueFileFilter.INSTANCE; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } } return FileUtils.listFiles(file, filter, directoryFilter).iterator(); } Collection<File> aux = new LinkedList<File>(); if (extensions == null) { aux.add(file); } return aux.iterator(); }
From source file:org.wso2.carbon.registry.governance.api.test.old.RXTTestBase.java
protected void loadRXTsForAssetModelSamples(String type) { try {//from www.j a v a2 s . c om String path = CarbonUtils.getCarbonHome() + File.separator + "samples" + File.separator + "asset-models" + File.separator + type + File.separator + "registry-extensions"; File parentFile = new File(path); File[] children = parentFile.listFiles((FileFilter) new SuffixFileFilter("rxt")); for (File file : children) { Resource resource = registry.newResource(); resource.setMediaType(GovernanceConstants.GOVERNANCE_ARTIFACT_CONFIGURATION_MEDIA_TYPE); String resourcePath = "repository/components/org.wso2.carbon.governance/types/" + file.getName(); byte[] fileContents; FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); fileContents = new byte[(int) file.length()]; fileInputStream.read(fileContents); } finally { if (fileInputStream != null) { fileInputStream.close(); } } resource.setContent(fileContents); registry.put(resourcePath, resource); OMElement element = AXIOMUtil .stringToOM(new String((byte[]) registry.get(resourcePath).getContent())); String shortName = element.getAttributeValue(new QName("shortName")); file = new File(configPath.replace(fileName, file.getName().replace("rxt", "metadata.xml"))); if (file.exists()) { fileInputStream = null; try { fileInputStream = new FileInputStream(file); fileContents = new byte[(int) file.length()]; fileInputStream.read(fileContents); } finally { if (fileInputStream != null) { fileInputStream.close(); } } OMElement contentElement = GovernanceUtils.buildOMElement(fileContents); GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); GenericArtifactManager manager = new GenericArtifactManager(registry, shortName); GenericArtifact artifact = manager.newGovernanceArtifact(contentElement); manager.addGenericArtifact(artifact); } } } catch (RegistryException e) { Assert.fail("Unable to populate RXT configuration", e); } catch (XMLStreamException e) { Assert.fail("Unable to parse RXT configuration"); } catch (IOException e) { Assert.fail("Unable to read asset payload"); } }
From source file:org.xmind.core.test.CompressionTest.java
public File[] getFileList(String inPath, String[] fileExtensions) { //List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true); List<File> listFiles = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(new File(inPath), new SuffixFileFilter(fileExtensions), //fileExtensions, null);/* w w w . j av a 2 s . co m*/ //TrueFileFilter.INSTANCE); File[] returnFileList = new File[listFiles.size()]; listFiles.toArray(returnFileList); return returnFileList; }
From source file:pl.otros.logview.loader.LogImportersLoaderTest.java
@Test public void testLoadPropertyFileBased() { LogImportersLoader importersLoader = new LogImportersLoader(); File pluginDir = new File("./files/plugins/logimporters"); Collection<LogImporter> loadPropertyFileBased = importersLoader.loadPropertyPatternFileFromDir(pluginDir); Assert.assertEquals(pluginDir.listFiles((FileFilter) new SuffixFileFilter("pattern")).length, loadPropertyFileBased.size()); }
From source file:rita.compiler.CompileString.java
/** * El mtodo compile crea el archivo compilado a partir de un codigo fuente * y lo deja en un directorio determinado * //from w ww . j ava2s . c o m * @param sourceCode * el codigo fuente * @param className * el nombre que debera llevar la clase * @param packageName * nombre del paquete * @param outputDirectory * directorio donde dejar el archivo compilado * */ public static final Collection<File> compile(File sourceCode, File outputDirectory) throws Exception { diagnostics = new ArrayList<Diagnostic<? extends JavaFileObject>>(); JavaCompiler compiler = new EclipseCompiler(); System.out.println(sourceCode); DiagnosticListener<JavaFileObject> listener = new DiagnosticListener<JavaFileObject>() { @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind().equals(javax.tools.Diagnostic.Kind.ERROR)) { System.err.println("=======================ERROR=========================="); System.err.println("Tipo: " + diagnostic.getKind()); System.err.println("mensaje: " + diagnostic.getMessage(Locale.ENGLISH)); System.err.println("linea: " + diagnostic.getLineNumber()); System.err.println("columna: " + diagnostic.getColumnNumber()); System.err.println("CODE: " + diagnostic.getCode()); System.err.println( "posicion: de " + diagnostic.getStartPosition() + " a " + diagnostic.getEndPosition()); System.err.println(diagnostic.getSource()); diagnostics.add(diagnostic); } } }; StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); /* guardar los .class y directorios (packages) en un directorio separado; de esta manera * si se genera mas de 1 clase (porque p.ej. hay inner classes en el codigo) podemos identificar * a todas las clases resultantes de esta compilacion */ File tempOutput = createTempDirectory(); fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tempOutput)); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(sourceCode); try { if (compiler.getTask(null, fileManager, listener, null, null, compilationUnits).call()) { // copiar .class y directorios (packages) generados por el compilador en tempOutput al directorio final FileUtils.copyDirectory(tempOutput, outputDirectory); // a partir de los paths de los archivos .class generados en el dir temp, modificarlos para que sean relativos a outputDirectory Collection<File> compilationResults = new ArrayList<File>(); final int tempPrefix = tempOutput.getAbsolutePath().length(); for (File classFile : FileUtils.listFiles(tempOutput, new SuffixFileFilter(".class"), TrueFileFilter.INSTANCE)) { compilationResults .add(new File(outputDirectory, classFile.getAbsolutePath().substring(tempPrefix))); } // retornar los paths de todos los .class generados return compilationResults; } } catch (Exception e) { e.printStackTrace(); System.out.println("Error al realizar el compilado"); } finally { FileUtils.deleteDirectory(tempOutput); fileManager.close(); } return null; }
From source file:ryerson.daspub.model.Submission.java
/** * Determine if submission is a PDF file. * @return True if submission is a PDF document, false otherwise. *//*from w w w. jav a2 s . c om*/ public boolean isPDF() { SuffixFileFilter sff = new SuffixFileFilter("pdf"); if (sff.accept(source)) { return true; } return false; }
From source file:spoon.IncrementalLauncher.java
private static Set<File> getAllJavaFiles(Set<File> resources) { Set<File> javaFiles = new HashSet<>(); for (File e : resources) { if (e.isDirectory()) { Collection<File> files = FileUtils.listFiles(e, new SuffixFileFilter(".java"), TrueFileFilter.INSTANCE); files.forEach(f -> {/*from ww w . j a va 2s . c om*/ try { javaFiles.add(f.getCanonicalFile()); } catch (IOException e1) { throw new SpoonException("unable to locate input source file: " + f); } }); } else if (e.isFile() && e.getName().endsWith(".java")) { try { javaFiles.add(e.getCanonicalFile()); } catch (IOException e1) { throw new SpoonException("unable to locate input source file: " + e); } } } return javaFiles; }
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);/*from w w w. j a va 2 s . co m*/ while (itr.hasNext()) { Path path = new Path(itr.next().getAbsolutePath()); relativeFilePaths.add(path.makeRelativeTo(root).toString()); } return relativeFilePaths; }
From source file:uk.co.danielrendall.imagetiler.gui.FileChoosers.java
public FileChoosers(ResourceMap appResourceMap) { openFileChooser = createFileChooser("openFileChooser", new FileFilter() { private final java.io.FileFilter delegate = new OrFileFilter(new SuffixFileFilter("bmp"), DirectoryFileFilter.INSTANCE); @Override/* w ww . j a v a2s . c o m*/ public boolean accept(File f) { return delegate.accept(f); } @Override public String getDescription() { return "BMP Files"; } }, appResourceMap); saveFileChooser = createFileChooser("saveFileChooser", new FileFilter() { private final java.io.FileFilter delegate = new SuffixFileFilter("svg"); @Override public boolean accept(File f) { return delegate.accept(f); } @Override public String getDescription() { return "SVG Files"; } }, appResourceMap); }