List of usage examples for org.apache.commons.vfs2 FileSelector FileSelector
FileSelector
From source file:org.pentaho.hadoop.shim.HadoopConfigurationLocator.java
/** * Attempt to find any Hadoop configuration as a direct descendant of the provided directory. * * @param baseDir Directory to look for Hadoop configurations in * @throws ConfigurationException//from w w w. jav a 2 s . c o m */ private void findHadoopConfigurations(FileObject baseDir, ActiveHadoopConfigurationLocator activeLocator) throws ConfigurationException { configurations = new HashMap<String, HadoopConfiguration>(); try { if (!baseDir.exists()) { throw new ConfigurationException(BaseMessages.getString(PKG, "Error.HadoopConfigurationDirectoryDoesNotExist", baseDir.getURL())); } for (FileObject f : baseDir.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getDepth() == 1 && FileType.FOLDER.equals(info.getFile().getType()); } @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { return info.getDepth() == 0; } })) { // Only load the specified configuration (ID should match the basename, we allow case-insensitivity) if (f.getName().getBaseName().equalsIgnoreCase(activeLocator.getActiveConfigurationId())) { HadoopConfiguration config = loadHadoopConfiguration(f); if (config != null) { configurations.put(config.getIdentifier(), config); } } } } catch (FileSystemException ex) { throw new ConfigurationException(BaseMessages.getString(PKG, "Error.UnableToLoadConfigurations", baseDir.getName().getFriendlyURI()), ex); } }
From source file:org.pentaho.hadoop.shim.HadoopConfigurationLocator.java
private List<URL> findJarsIn(FileObject path, final int maxdepth, final Set<String> paths) throws FileSystemException { FileObject[] jars = path.findFiles(new FileSelector() { @Override//from ww w.j a v a 2 s.co m public boolean includeFile(FileSelectInfo info) throws Exception { for (String path : paths) { if (info.getFile().getURL().toString().endsWith(path)) { return false; } } return info.getFile().getName().getBaseName().endsWith(JAR_EXTENSION); } @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { for (String path : paths) { if (info.getFile().getURL().toString().endsWith(path)) { return false; } } return info.getDepth() <= maxdepth; } }); List<URL> jarUrls = new ArrayList<URL>(); for (FileObject jar : jars) { jarUrls.add(jar.getURL()); } return jarUrls; }
From source file:org.renjin.primitives.files.Files.java
@Internal("file.copy") public static LogicalVector fileCopy(@Current Context context, StringVector fromFiles, String to, boolean overwrite, final boolean recursive) throws FileSystemException { LogicalArrayVector.Builder result = new LogicalArrayVector.Builder(); FileObject toFile = context.resolveFile(to); for (String from : fromFiles) { try {// w w w . j a v a 2 s .c o m toFile.copyFrom(context.resolveFile(from), new FileSelector() { @Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo fileInfo) throws Exception { return recursive; } }); result.add(true); } catch (FileSystemException e) { result.add(false); } } return result.build(); }
From source file:sf.net.experimaestro.manager.js.ScriptTest.java
/** * Retrieves all the .js files (excluding .inc.js) * @return/* w w w . jav a 2 s. co m*/ * @throws IOException */ @Factory public Object[] jsFactories() throws IOException { XPMEnvironment environment = new XPMEnvironment(); final String testFile = System.getProperty(JS_TEST_FILE_KEY); // Get the JavaScript files final URL url = ScriptTest.class.getResource(JS_SCRIPT_PATH); FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.resolveFile(url.toExternalForm()); FileObject[] files = dir.findFiles(new FileSelector() { @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo file) throws Exception { String name = file.getFile().getName().getBaseName(); if (testFile != null) return name.equals(testFile); return name.endsWith(".js") && !name.endsWith(".inc.js"); } }); Object[] r = new Object[files.length]; for (int i = r.length; --i >= 0;) r[i] = new JavaScriptChecker(environment, files[i]); return r; }