List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:gov.redhawk.sca.efs.server.tests.FileSystemImplTest.java
/** * Test method for/* ww w . j a v a2 s .c o m*/ * {@link gov.redhawk.efs.sca.server.internal.FileSystemImpl#list(java.lang.String)} * . */ @Test public void testList() { try { Assert.assertEquals(0, this.fileSystem.list("empty").length); FileInformationType[] result = this.fileSystem.list("*"); Assert.assertEquals(FileSystemImplTest.root.list().length, result.length); for (final FileInformationType type : result) { final File subFile = new File(FileSystemImplTest.root, type.name); if (subFile.isDirectory()) { Assert.assertEquals(FileType.DIRECTORY, type.kind); } else { Assert.assertEquals(FileType.PLAIN, type.kind); } } result = this.fileSystem.list("subFolder/test*"); final File subRoot = new File(FileSystemImplTest.root, "subFolder"); Assert.assertEquals(subRoot.list(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { if (!dir.equals(subRoot)) { return false; } return FilenameUtils.wildcardMatch(name, "test*"); } }).length, result.length); for (final FileInformationType type : result) { final File subFile = new File(subRoot, type.name); if (subFile.isDirectory()) { Assert.assertEquals(FileType.DIRECTORY, type.kind); } else { Assert.assertEquals(FileType.PLAIN, type.kind); } } result = this.fileSystem.list("testFile.t??"); Assert.assertEquals(1, result.length); Assert.assertEquals(FileType.PLAIN, result[0].kind); } catch (final FileException e) { Assert.fail(e.getMessage() + ": " + e.msg); } catch (final InvalidFileName e) { Assert.fail(e.getMessage() + ": " + e.msg); } }
From source file:org.saiku.plugin.resources.PluginResource.java
private List<File> getJsFiles(File rootDir) { List<File> result = new ArrayList<File>(); File[] files = rootDir.listFiles(new FilenameFilter() { public boolean accept(File file, String name) { return name.endsWith(".js"); }/* w ww. j a va2s . c o m*/ }); if (files != null) result.addAll(Arrays.asList(files)); File[] folders = rootDir.listFiles(new FilenameFilter() { public boolean accept(File file, String name) { return file.isDirectory(); } }); if (folders != null) { for (File f : folders) { List<File> partial = getJsFiles(f); if (partial != null) result.addAll(partial); } } return result; }
From source file:com.apress.dwrprojects.fileman.FileSystemFunctions.java
/** * This method is called to list all the file system roots on the system. * * @return A List of DirectoryVO objects, one for each file system * root on the system. * @throws Exception If anything goes wrong. *//*from w ww. j ava 2 s . c om*/ public List listRoots() throws Exception { try { File[] roots = File.listRoots(); List<DirectoryVO> results = new ArrayList<DirectoryVO>(); for (final File f : roots) { DirectoryVO dv = new DirectoryVO(); dv.setName(f.getPath()); dv.setPath(f.getPath()); // See if the directory has child directories or not. Anonymous inner // class used to determine whether the directory has children or not. String[] childDirectories = f.list(new FilenameFilter() { public boolean accept(final File inDir, final String inName) { if (inName != f.getName()) { File f = new File(inDir.getPath() + File.separator + inName); if (f.isDirectory()) { return true; } else { return false; } } else { return false; } } }); // Setting whether the directory has children or not is used by the UI // code to set up the grid properly in terms of nodes being expandable // or not. if (childDirectories != null && childDirectories.length > 0) { dv.setHasChildren(true); } results.add(dv); } return results; } catch (Exception e) { throw new Exception("Exception occurred: " + e); } }
From source file:com.liferay.blade.cli.InitCommand.java
private void moveContentsToDir(File src, File dest) throws IOException { final String ignoreName = dest.getName(); File[] filesToCopy = src.listFiles(new FilenameFilter() { @Override/* ww w . java 2 s . c o m*/ public boolean accept(File dir, String name) { return !name.equals(".git") && !name.equals(ignoreName); } }); dest.mkdirs(); for (File fileToCopy : filesToCopy) { IO.copy(fileToCopy, new File(dest, fileToCopy.getName())); IO.deleteWithException(fileToCopy); } }
From source file:com.runwaysdk.dataaccess.io.Backup.java
private void backupWebapp() { File backupProfileLocationFile = new File( this.tempBackupFileLocation + File.separator + WEBAPP_DIR_NAME + File.separator); String webappRootDir = DeployProperties.getDeployPath(); File webappRootFile = new File(webappRootDir); FilenameFilter filenameFilter = new FilenameFilter() { public boolean accept(File dir, String name) { if (name.endsWith(".svn") || dir.getName().startsWith(".")) { return false; }/*from ww w. jav a 2s . c om*/ return true; } }; boolean success = FileIO.copyFolder(webappRootFile, backupProfileLocationFile, filenameFilter); if (!success) { // TODO : This success stuff is garbage, I want the actual IOException why swallow it CreateBackupException cbe = new CreateBackupException(); cbe.setLocation(backupProfileLocationFile.getAbsolutePath()); throw cbe; } }
From source file:io.stallion.services.DynamicSettings.java
public void loadAll() { if (dbAvailable) { loadUpdated(null);//from w ww . j a v a 2 s.c om } else { File[] files = new File(directory).listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".json"); } }); for (File file : files) { try { String group = FilenameUtils.getBaseName(file.getAbsolutePath()); String json = FileUtils.readFileToString(file, "UTF8"); settingsMap.put(group, JSON.parseMap(json)); settingsParsedObjectMap.put(group, map()); } catch (IOException e) { throw new RuntimeException(e); } } } }
From source file:cn.calm.osgi.conter.FelixOsgiHost.java
/** * Return a list of directories under a directory whose name is a number *//*from ww w . j a va 2 s. c om*/ protected Map<String, String> getRunLevelDirs(String dir) { Map<String, String> dirs = new HashMap<String, String>(); try { URL url = resource.find("bundles"); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); String[] runLevelDirs = bundlesDir.list(new FilenameFilter() { public boolean accept(File file, String name) { try { return file.isDirectory() && Integer.valueOf(name) > 0; } catch (NumberFormatException ex) { // the name is not a number return false; } } }); if (runLevelDirs != null && runLevelDirs.length > 0) { // add all the dirs to the list for (String runLevel : runLevelDirs) dirs.put(runLevel, StringUtils.removeEnd(dir, "/") + "/" + runLevel); } else if (LOG.isDebugEnabled()) { LOG.debug("No run level directories found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) LOG.warn("Unable to read [#0] directory", dir); } else if (LOG.isWarnEnabled()) LOG.warn("The [#0] directory was not found", dir); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Unable load bundles from the [#0] directory", e, dir); } return dirs; }
From source file:com.hunch.ImageManager.java
protected FileInputStream getImageFileStreamFromCache(final Context context, final URL url) { final String fileName = fileNameFromURL(url); File hunchCacheDir = new File(context.getCacheDir(), Const.CACHE_IMG_DIR); File[] imageFileList = hunchCacheDir.listFiles(new FilenameFilter() { @Override//w w w .j a v a 2s .c o m public boolean accept(File dir, String aFilename) { return aFilename.equals(fileName); } }); if (imageFileList == null || imageFileList.length == 0) { return null; } if (imageFileList.length > 1) { Log.i(Const.TAG, "found " + imageFileList.length + " images for url in app cache! " + "(" + fileName + ")"); } FileInputStream iStream = null; try { iStream = new FileInputStream(imageFileList[0]); } catch (FileNotFoundException e) { return null; } //Log.v( Const.TAG, "found image in app cache (" + url + ")" ); return iStream; }
From source file:mt.RansacFileChooser.java
public void Singlefile() { File[] Averagefiles = chooserA.getSelectedFile().listFiles(new FilenameFilter() { @Override//w w w. ja va2s . c o m public boolean accept(File pathname, String filename) { return (filename.endsWith(".txt") && !filename.contains("Rates") && filename.contains("Average") && !filename.contains("All")); } }); File singlefile = new File( chooserA.getSelectedFile() + "//" + "Final_Experimental_results" + "All" + ".txt"); try { FileWriter fw = new FileWriter(singlefile); BufferedWriter bw = new BufferedWriter(fw); bw.write( "\tAverageGrowthrate(px)\tAverageShrinkrate(px)\tCatastropheFrequency(px)\tRescueFrequency(px)\n"); for (int i = 0; i < Averagefiles.length; ++i) { File file = Averagefiles[i]; try { BufferedReader in = Util.openFileRead(file); while (in.ready()) { String line = in.readLine().trim(); while (line.contains("\t\t")) line = line.replaceAll("\t\t", "\t"); if (line.length() >= 3 && line.matches("[0-3].*")) { final String[] split = line.trim().split("\t"); final double growthrate = Double.parseDouble(split[0]); final double shrinkrate = Double.parseDouble(split[1]); final double catfrequ = Double.parseDouble(split[2]); final double resfrequ = Double.parseDouble(split[3]); if (growthrate > 0 || shrinkrate < 0 || catfrequ > 0 || resfrequ > 0) bw.write("\t" + (growthrate) + "\t" + "\t" + "\t" + "\t" + (shrinkrate) + "\t" + "\t" + "\t" + (catfrequ) + "\t" + "\t" + "\t" + (resfrequ) + "\n" + "\n"); } } } catch (Exception e) { e.printStackTrace(); } } bw.close(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }