List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:hudson.matrix.MatrixProject.java
/** * Recursively search for configuration and put them to the map * * <p> The directory structure would be <tt>axis-a/b/axis-c/d/axis-e/f</tt> * for combination [a=b,c=d,e=f]. Note that two combinations [a=b,c=d] and * [a=b,c=d,e=f] can both co-exist (where one is an archived record and the * other is live, for example) so search needs to be thorough. * * @param dir Directory to be searched.//www .j ava 2s. co m * @param result Receives the loaded {@link MatrixConfiguration}s. * @param combination Combination of key/values discovered so far while * traversing the directories. Read-only. */ private void loadConfigurations(File dir, CopyOnWriteMap.Tree<Combination, MatrixConfiguration> result, Map<String, String> combination) { File[] axisDirs = dir.listFiles(new FileFilter() { public boolean accept(File child) { return child.isDirectory() && child.getName().startsWith("axis-"); } }); if (axisDirs == null) { return; } for (File subdir : axisDirs) { String axis = subdir.getName().substring(5); // axis name File[] valuesDir = subdir.listFiles(new FileFilter() { public boolean accept(File child) { return child.isDirectory(); } }); if (valuesDir == null) { continue; // no values here } for (File v : valuesDir) { Map<String, String> c = new HashMap<String, String>(combination); c.put(axis, TokenList.decode(v.getName())); try { XmlFile config = Items.getConfigFile(v); if (config.exists()) { Combination comb = new Combination(c); // if we already have this in memory, just use it. // otherwise load it MatrixConfiguration item = null; if (this.configurations != null) { item = this.configurations.get(comb); } if (item == null) { item = (MatrixConfiguration) config.read(); item.setCombination(comb); item.onLoad(this, v.getName()); } result.put(item.getCombination(), item); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to load matrix configuration " + v, e); } loadConfigurations(v, result, c); } } }
From source file:edu.cornell.mannlib.vitro.webapp.filestorage.impl.FileStorageImpl.java
/** * <p>/*w ww . j a v a 2s .c o m*/ * For a non-null result, a directory must exist for the ID, and it must * contain a file (it may or may not contain other directories). * </p> */ public String getFilename(String id) { File dir = FileStorageHelper.getPathToIdDirectory(id, this.namespacesMap, this.rootDir); log.debug("ID '" + id + "' translates to this directory path: '" + dir + "'"); if ((!dir.exists()) || (!dir.isDirectory())) { return null; } File[] files = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile(); } }); if (files.length == 0) { return null; } if (files.length > 1) { throw new IllegalStateException( "More than one file associated with ID: '" + id + "', directory location '" + dir + "'"); } return FileStorageHelper.decodeName(files[0].getName()); }
From source file:org.apache.carbondata.sdk.file.AvroCarbonWriterTest.java
@Test public void testWriteComplexRecord() throws IOException, InvalidLoadOptionException { FileUtils.deleteDirectory(new File(path)); String mySchema = "{" + " \"name\": \"address\", " + " \"type\": \"record\", " + " \"fields\": [ " + " { \"name\": \"name\", \"type\": \"string\"}, " + " { \"name\": \"age\", \"type\": \"int\"}, " + " { " + " \"name\": \"address\", " + " \"type\": { " + " \"type\" : \"record\", " + " \"name\" : \"my_address\", " + " \"fields\" : [ " + " {\"name\": \"street\", \"type\": \"string\"}, " + " {\"name\": \"city\", \"type\": \"string\"} " + " ]} " + " }, " + " {\"name\" :\"doorNum\", " + " \"type\" : { " + " \"type\" :\"array\", " + " \"items\":{ " + " \"name\" :\"EachdoorNums\", " + " \"type\" : \"int\", " + " \"default\":-1} " + " } " + " }] " + "}"; String json = "{\"name\":\"bob\", \"age\":10, \"address\" : {\"street\":\"abc\", \"city\":\"bang\"}, " + " \"doorNum\" : [1,2,3,4]}"; WriteAvroComplexData(mySchema, json, null); File[] dataFiles = new File(path).listFiles(new FileFilter() { @Override/*from w w w. j a va2 s .co m*/ public boolean accept(File pathname) { return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT); } }); Assert.assertNotNull(dataFiles); Assert.assertEquals(1, dataFiles.length); FileUtils.deleteDirectory(new File(path)); }
From source file:net.javacoding.xsearch.config.ServerConfiguration.java
/** * Synchronizes dataset configuration file entries in the server configuration file with the file system. *///from w w w. j a v a2 s.c o m public void syncDatasets(boolean forceRefresh) { // scan the base directory for new dataset configuration files File[] _files = getBaseDirectory().listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith("-dataset-config.xml") && !pathname.isDirectory(); } }); if (_files != null) { for (int i = 0; i < _files.length; i++) { String fileName = _files[i].getName(); addDatasetConfigurationFile(fileName.substring(0, fileName.length() - 19), forceRefresh); } } dcs = null; }
From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java
public static String[] getAllSnapshotFilenames(final ServletConfig config, final TranscodeRequest request) throws ProcessorException { FileFilter fileFilter = new FileFilter() { @Override/*w w w .j a va 2 s.c om*/ public boolean accept(File pathname) { boolean matchesPid = pathname.getName().contains(request.getPid()); boolean matchesFormat = pathname.getName() .endsWith(Util.getInitParameter(config, Constants.SNAPSHOT_FINAL_FORMAT)); return matchesFormat && matchesPid; } }; File[] allFiles = getOutputDir(request, config).listFiles(fileFilter); String[] filenames = new String[allFiles.length]; for (int i = 0; i < allFiles.length; i++) { filenames[i] = Util.getRelativePath(OutputFileUtil.getBaseOutputDir(request, config), allFiles[i]); } return filenames; }
From source file:edu.stanford.epad.common.util.EPADFileUtils.java
public static List<File> getAllFilesWithoutExtension(File dir, final String extension) { File[] files = dir.listFiles(new FileFilter() { @Override// ww w. j a v a2s . c om public boolean accept(File file) { return !file.getName().endsWith(extension); } }); if (files != null) { return Arrays.asList(files); } else { return new ArrayList<File>(); // return an empty list of no files. } }
From source file:fr.gouv.culture.vitam.droid.DroidHandler.java
public static final void cleanTempFiles() { File tmpDir = new File(System.getProperty("java.io.tmpdir")); File[] todelete = tmpDir.listFiles(new FileFilter() { @Override/*from w w w. j a v a 2 s . com*/ public boolean accept(File arg0) { String name = arg0.getName(); return (name.endsWith(".tmp") && (name.startsWith(StaticValues.PREFIX_TEMPFILE) || name.startsWith("droid-archive"))); } }); for (File file : todelete) { if (!file.delete()) { file.deleteOnExit(); } } }
From source file:ch.entwine.weblounge.contentrepository.impl.fs.FileSystemContentRepository.java
/** * {@inheritDoc}//from w w w . j ava2 s . c om * * @see ch.entwine.weblounge.contentrepository.impl.AbstractContentRepository#loadResourceContent(ch.entwine.weblounge.common.content.ResourceURI, * ch.entwine.weblounge.common.language.Language) */ @Override protected InputStream loadResourceContent(ResourceURI uri, Language language) throws ContentRepositoryException, IOException { File resourceFile = uriToFile(uri); if (resourceFile == null) return null; // Look for the localized file File resourceDirectory = resourceFile.getParentFile(); final String filenamePrefix = language.getIdentifier() + "."; File[] localizedFiles = resourceDirectory.listFiles(new FileFilter() { public boolean accept(File f) { return f.isFile() && f.getName().startsWith(filenamePrefix); } }); // Make sure everything looks consistent if (localizedFiles == null || localizedFiles.length == 0) return null; if (localizedFiles != null && localizedFiles.length > 1) logger.warn("Inconsistencies found in resource {} content {}", language, uri); // Finally return the content return new FileInputStream(localizedFiles[0]); }
From source file:com.streamsets.datacollector.cluster.ClusterProviderImpl.java
private static File getBootstrapJar(File bootstrapDir, final String name) { Utils.checkState(bootstrapDir.isDirectory(), Utils.format("SDC bootstrap lib does not exist: {}", bootstrapDir)); File[] candidates = bootstrapDir.listFiles(new FileFilter() { @Override// w w w.ja va 2 s .co m public boolean accept(File candidate) { final String filename = candidate.getName(); return filename.startsWith(name) && filename.endsWith(".jar"); } }); Utils.checkState(candidates != null, Utils.format("Did not find jar matching {} in {}", name, bootstrapDir)); Utils.checkState(candidates.length == 1, Utils.format("Did not find exactly one bootstrap jar: {}", Arrays.toString(candidates))); return candidates[0]; }
From source file:com.evolveum.midpoint.init.InitialDataImport.java
private File[] getInitialImportObjects() { URL path = InitialDataImport.class.getClassLoader().getResource("initial-objects"); String resourceType = path.getProtocol(); File[] files = null;//from w ww . ja v a2 s .com File folder = null; if ("zip".equals(resourceType) || "jar".equals(resourceType)) { try { File tmpDir = new File(configuration.getMidpointHome() + "/tmp"); if (!tmpDir.mkdir()) { LOGGER.warn( "Failed to create temporary directory for inital objects {}. Maybe it already exists", configuration.getMidpointHome() + "/tmp"); } tmpDir = new File(configuration.getMidpointHome() + "/tmp/initial-objects"); if (!tmpDir.mkdir()) { LOGGER.warn( "Failed to create temporary directory for inital objects {}. Maybe it already exists", configuration.getMidpointHome() + "/tmp/initial-objects"); } //prerequisite: we are expecting that the files are store in the same archive as the source code that is loading it URI src = InitialDataImport.class.getProtectionDomain().getCodeSource().getLocation().toURI(); LOGGER.trace("InitialDataImport code location: {}", src); Map<String, String> env = new HashMap<>(); env.put("create", "false"); URI normalizedSrc = new URI(src.toString().replaceFirst("file:", "jar:file:")); LOGGER.trace("InitialDataImport normalized code location: {}", normalizedSrc); try (FileSystem zipfs = FileSystems.newFileSystem(normalizedSrc, env)) { Path pathInZipfile = zipfs.getPath("/initial-objects"); //TODO: use some well defined directory, e.g. midPoint home final Path destDir = Paths.get(configuration.getMidpointHome() + "/tmp"); Files.walkFileTree(pathInZipfile, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { final Path destFile = Paths.get(destDir.toString(), file.toString()); LOGGER.trace("Extracting file {} to {}", file, destFile); Files.copy(file, destFile, StandardCopyOption.REPLACE_EXISTING); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final Path dirToCreate = Paths.get(destDir.toString(), dir.toString()); if (Files.notExists(dirToCreate)) { LOGGER.trace("Creating directory {}", dirToCreate); Files.createDirectory(dirToCreate); } return FileVisitResult.CONTINUE; } }); } folder = new File(configuration.getMidpointHome() + "/tmp/initial-objects"); } catch (IOException ex) { throw new RuntimeException( "Failed to copy initial objects file out of the archive to the temporary directory", ex); } catch (URISyntaxException ex) { throw new RuntimeException("Failed get URI for the source code bundled with initial objects", ex); } } if ("file".equals(resourceType)) { folder = getResource("initial-objects"); } files = folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isDirectory()) { return false; } return true; } }); Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { int n1 = getNumberFromName(o1); int n2 = getNumberFromName(o2); return n1 - n2; } }); return files; }