List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:com.github.ipaas.ifw.front.FisResource.java
private static void registerAll(String resMappingFileDir) throws FisException { String configDirPath = FisResource.class.getClassLoader().getResource(resMappingFileDir).getFile(); File mapJsonDir = new File(configDirPath); String[] mapJsonFiles = mapJsonDir.list(); FilenameFilter defaultFileNameFilter = new FilenameFilter() { public boolean accept(File dir, String name) { boolean isMatch = name.equals(DEFAULT_RES_MAPPING_FILE); return isMatch; }/* w ww.ja va 2 s. com*/ }; FilenameFilter nameSpaceFileNameFilter = new FilenameFilter() { public boolean accept(File dir, String name) { boolean isMatch = name.endsWith("-" + DEFAULT_RES_MAPPING_FILE); return isMatch; } }; String[] childrenFileNames = mapJsonDir.list(defaultFileNameFilter); String[] nameSpacechildrenFileNames = mapJsonDir.list(nameSpaceFileNameFilter); if ((null == childrenFileNames || 0 == childrenFileNames.length) && (null == nameSpacechildrenFileNames || 0 == nameSpacechildrenFileNames.length)) { throw new FisException("Resource Mapping File Not Found!"); } // ? if (null != childrenFileNames || 0 < childrenFileNames.length) { for (int i = 0; i < childrenFileNames.length; i++) { FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, FisResource.DEFAULT_NS_GLOBAL); } } // ??? if (null != nameSpacechildrenFileNames || 0 < nameSpacechildrenFileNames.length) { for (int i = 0; i < nameSpacechildrenFileNames.length; i++) { String fileName = nameSpacechildrenFileNames[i]; int pos = fileName.indexOf("-" + FisResource.DEFAULT_RES_MAPPING_FILE); String namespace = fileName.substring(0, pos); FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, namespace); } } // for (int i = 0, len = mapJsonFiles.length; i < len; i++) { // String fileName = mapJsonFiles[i]; // if (fileName.equals(FisResource.DEFAULT_RES_MAPPING_FILE)) { // FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, // FisResource.DEFAULT_NS_GLOBAL); // } else { // int pos = fileName.indexOf("-" + // FisResource.DEFAULT_RES_MAPPING_FILE); // if (pos > 0) { // String namespace = fileName.substring(0, pos); // FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, // namespace); // } // } // } }
From source file:com.runwaysdk.dataaccess.io.Restore.java
private void restoreWebapp() { File backupProfileLocationFile = new File( this.restoreDirectory.getPath() + File.separator + Backup.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; }/*www . j a va2 s . co m*/ return true; } }; FileFilter fileFilter = new FileFilter() { public boolean accept(File pathname) { return true; } }; try { this.logPrintStream.println("\n" + ServerExceptionMessageLocalizer .cleaningWebappFolderMessage(Session.getCurrentLocale(), webappRootFile)); FileIO.deleteFolderContent(webappRootFile, fileFilter); } catch (IOException e) { // Some files might have already been deleted. We will copy anyway, as the // files should overwrite. } boolean success = FileIO.copyFolder(backupProfileLocationFile, webappRootFile, filenameFilter, this.logPrintStream); if (!success) { // TODO : This success stuff is garbage, I want the actual IOException why swallow it BackupReadException bre = new BackupReadException(); bre.setLocation(webappRootFile.getAbsolutePath()); throw bre; } }
From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.actions.ModelMigrationHelper.java
public static List<File> getModels(IProject source, final String[] fileExt) { File projectHome = IFileHelper.convertIRessourceToFile(source); FilenameFilter filter = new FilenameFilter() { public boolean accept(File file, String name) { boolean ok = false; for (String string : fileExt) { if (name.endsWith(string)) { ok = true;/*w w w . j a va 2 s .com*/ break; } } return file.isFile() && ok; } }; List<File> files = FileHelper.listAll(projectHome); List<File> models = new ArrayList<File>(); for (File file : files) { if (filter.accept(file, file.getName())) { models.add(file); } } return models; }
From source file:gov.pnnl.goss.gridappsd.app.AppManagerImpl.java
protected void scanForApps() { // Get directory for apps from the config File appConfigDir = getAppConfigDirectory(); // for each app found, parse the appinfo.config file to create appinfo // object and add to apps map File[] appConfigFiles = appConfigDir.listFiles(new FilenameFilter() { @Override//from www. j a v a2 s.com public boolean accept(File dir, String name) { return name.endsWith(CONFIG_FILE_EXT); } }); for (File appConfigFile : appConfigFiles) { AppInfo appInfo = parseAppInfo(appConfigFile); apps.put(appInfo.getId(), appInfo); } }
From source file:com.freedomotic.plugins.impl.PluginsManagerImpl.java
/** * Load the resources linked to a plugin package. Note a plugin package may * be composed of more than one plugin, so resources must be added just once * for every package./*from w w w . j av a 2s . c o m*/ * */ private void loadPluginResources(File directory) throws PluginLoadingException { //now loadBoundle data for this jar (can contain more than one plugin) //resources are mergend in the default resources folder commandRepository.loadCommands(new File(directory + "/data/cmd")); triggers.loadTriggers(new File(directory + "/data/trg")); reactionRepository.loadReactions(new File(directory + "/data/rea")); //create ad-hoc subfolders of temp File destination = new File(Info.PATHS.PATH_RESOURCES_FOLDER + "/temp/" + directory.getName()); destination.mkdir(); recursiveCopy(new File(directory + "/data/resources"), destination); File templatesFolder = new File(directory + "/data/templates/"); if (templatesFolder.exists()) { LOG.info("Loading object templates from {}", templatesFolder.getAbsolutePath()); //for every envobject class a placeholder is created File[] templates = templatesFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return (name.endsWith(".xobj")); } }); for (File template : templates) { Client placeholder; try { placeholder = clientStorage.createObjectPlaceholder(template); placeholder = mergePackageConfiguration(placeholder, directory); clientStorage.add(placeholder); } catch (RepositoryException ex) { throw new PluginLoadingException("Cannot create object plugin " + "placeholder from template " + template.getAbsolutePath(), ex); } catch (IOException ex) { throw new PluginLoadingException( "Missing PACKAGE info" + "for template at " + template.getAbsolutePath(), ex); } } } else { LOG.debug("No object templates to load from {}", templatesFolder.getAbsolutePath()); } }
From source file:com.naryx.tagfusion.cfm.document.cfDOCUMENT.java
private void resolveFonts(cfSession _Session, ITextRenderer _renderer) throws dataNotSupportedException, cfmRunTimeException { ITextFontResolver resolver = _renderer.getFontResolver(); boolean embed = getDynamic(_Session, "FONTEMBED").getBoolean(); for (int i = 0; i < defaultFontDirs.length; i++) { File nextFontDir = new File(defaultFontDirs[i]); File[] fontFiles = nextFontDir.listFiles(new FilenameFilter() { public boolean accept(File _dir, String _name) { String name = _name.toLowerCase(); return name.endsWith(".otf") || name.endsWith(".ttf"); }//from w ww . j av a2 s . com }); if (fontFiles != null) { for (int f = 0; f < fontFiles.length; f++) { try { resolver.addFont(fontFiles[f].getAbsolutePath(), BaseFont.IDENTITY_H, embed); } catch (Exception ignored) { } // ignore fonts that can't be added } } } }
From source file:com.sinosoft.one.mvc.web.instruction.ViewInstruction.java
/** * /*from ww w . ja v a 2s . c o m*/ * @param fileNameToFind * @param directoryFile * @param ignoreCase * @return */ private String searchViewFile(File directoryFile, final String fileNameToFind, final boolean ignoreCase) { String[] viewFiles = directoryFile.list(new FilenameFilter() { public boolean accept(File dir, String fileName) { String _notDirectoryViewName = fileNameToFind; String _fileName = fileName; if (ignoreCase) { _fileName = fileName.toLowerCase(); _notDirectoryViewName = fileNameToFind.toLowerCase(); } // ? if (_fileName.startsWith(_notDirectoryViewName) && new File(dir, fileName).isFile()) { if (fileName.length() == fileNameToFind.length() && fileNameToFind.lastIndexOf('.') != -1) { return true; } if (fileName.length() > fileNameToFind.length() && fileName.charAt(fileNameToFind.length()) == '.') { return true; } } return false; } }); Arrays.sort(viewFiles); return viewFiles.length == 0 ? null : viewFiles[0]; }
From source file:com.otway.picasasync.syncutil.AlbumSync.java
private List<ImageSync> buildImageList(PicasawebClient webClient, File localFolder, AlbumEntry albumEntry, final LocalDateTime oldestDate) throws IOException, ServiceException { List<ImageSync> allImages = new ArrayList<ImageSync>(); syncManager.getSyncState().setStatus("Querying Google for album " + albumEntry.getTitle().getPlainText()); // Get the list of remote photos List<PhotoEntry> photos = webClient.getPhotos(albumEntry); // Deal with the fact that an album can have multiple images with the same local filename. HashMap<String, List<PhotoEntry>> fileGroups = new HashMap<String, List<PhotoEntry>>(); for (PhotoEntry photo : photos) { String imageName = photo.getTitle().getPlainText().toLowerCase(); if (FilenameUtils.getExtension(imageName).toLowerCase().equals(".mov")) { log.info("Skipping file " + imageName + " with .mov file extension."); continue; }/*from w ww . j a v a 2s.com*/ List<PhotoEntry> photoList = null; if (!fileGroups.containsKey(imageName)) { photoList = new ArrayList<PhotoEntry>(); fileGroups.put(imageName, photoList); } else photoList = fileGroups.get(imageName); photoList.add(photo); } // So now we have a map of image name => List of photo entries which use that name. List<PhotoEntry> nonDupePhotos = new ArrayList<PhotoEntry>(); int dupesDiscarded = 0; for (List<PhotoEntry> list : fileGroups.values()) { String maxId = null; PhotoEntry photoToUse = null; for (PhotoEntry photo : list) { String id = PicasawebClient.getPhotoId(photo); // We'll arbitrarily pick the one with the lowest ID, and ignore the rest. if (maxId == null || maxId.compareTo(id) == -1) { maxId = id; photoToUse = photo; } } nonDupePhotos.add(photoToUse); dupesDiscarded += list.size() - 1; } if (dupesDiscarded > 0) { log.info("Ignoring " + dupesDiscarded + " duplicate photos of " + photos.size() + " from album " + getAlbumName()); } List<ImageSync> remoteImages = new ArrayList<ImageSync>(); for (PhotoEntry photo : nonDupePhotos) { String imageFile = photo.getTitle().getPlainText(); if (settings.getExcludeVideos() && photo.getMediaContents().size() > 1) { log.info("Exclude Video enabled: skipping " + imageFile); continue; } File localFileName = new File(localFolder, imageFile); remoteImages.add(new ImageSync(photo, localFileName)); } log.debug(remoteImages.size() + " remote images found in " + albumEntry.getTitle().getPlainText()); // Get the local file list File[] files = localFolder.listFiles(new FilenameFilter() { public boolean accept(File current, String name) { File file = new File(current, name); return file.isFile() && !file.isHidden(); } }); List<ImageSync> localFiles = new ArrayList<ImageSync>(); if (files != null && files.length > 0) { log.info(files.length + " local files found in " + localFolder); // Now, pull out all the local files that aren't in the list. // These are the new files that we'll upload for (File localFile : files) { if (!fileGroups.containsKey(localFile.getName().toLowerCase())) { localFiles.add(new ImageSync(null, localFile)); } } } log.debug(localFiles.size() + " local images found in " + localFolder); allImages.addAll(localFiles); // Add the remote images after. Uploads are higher priority than downloads allImages.addAll(remoteImages); log.debug(allImages.size() + " images found (new local + remote)"); // And finally, filter out anything that's too old. List<ImageSync> result = new ArrayList<ImageSync>(); for (ImageSync image : allImages) if (image.newerThan(oldestDate)) result.add(image); log.debug(result.size() + " total images after date filter applied."); return result; }
From source file:edu.unc.lib.dl.cdr.services.model.FailedEnhancementMap.java
/** * Recreates the failed services map from the structure on disk, but does not load the actual contents *///from w ww.ja v a2 s .co m public synchronized void loadFailedMap() { File baseFolder = new File(this.failureLogPath); String[] directories = baseFolder.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return new File(dir, name).isDirectory(); } }); // Create pid entries for each directory for (String directory : directories) { File pidFolder = new File(baseFolder, directory); String[] pidFiles = pidFolder.list(); Map<String, WeakReference<FailedEnhancementEntry>> serviceCache = new HashMap<String, WeakReference<FailedEnhancementEntry>>(); this.pidToService.put(directory, serviceCache); // Scan the subfolders of the pid directories for which particular services failed for (String pidFile : pidFiles) { if (pidFile.startsWith(ERROR_FILE_PREFIX)) { String serviceName = pidFile.substring(ERROR_FILE_PREFIX.length()); // Store a stub for the pid -> service mapping serviceCache.put(serviceName, null); Map<String, WeakReference<FailedEnhancementEntry>> pidCache = this.serviceToPID .get(serviceName); if (pidCache == null) { pidCache = new HashMap<String, WeakReference<FailedEnhancementEntry>>(); this.serviceToPID.put(serviceName, pidCache); } // Store a stub for the service to pid mapping pidCache.put(directory, null); } } } }
From source file:fr.ens.transcriptome.corsen.Corsen.java
/** * Execute corsen CLI in batch mode with batch file *///from w w w . j a v a 2 s . c om public static void executeBatchFile() { final long startTime = System.currentTimeMillis(); final List<String[]> dirs = new ArrayList<String[]>(); boolean error = false; try { final FileReader fr = new FileReader(batchFile); BufferedReader br = new BufferedReader(fr); String line = null; boolean first = true; while ((line = br.readLine()) != null) { if (first) { first = false; continue; } String[] fields = line.split("\t"); File dir = new File(fields[0]); final String prefixA = fields[1]; final String prefixB = fields[2]; if (!dir.exists()) { error = true; System.err.println("Directory not found : " + dir.getAbsolutePath()); } else { File[] filesA = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.startsWith(prefixA); } }); File[] filesB = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.startsWith(prefixB); } }); if (filesA == null || filesA.length == 0) { System.err.println("Prefix a: " + prefixA + " in directory " + dir.getAbsolutePath()); error = true; } if (filesB == null || filesB.length == 0) { System.err.println("Prefix b: " + prefixB + " in directory " + dir.getAbsolutePath()); error = true; } } dirs.add(new String[] { fields[0], fields[1], fields[2] }); } br.close(); } catch (IOException e) { System.err.println("Error while reading batch file: " + batchFile); } if (!error) for (String[] fields : dirs) CLIGui.main(new String[] { fields[1], fields[2], fields[0] }); final long endTime = System.currentTimeMillis(); final long totalTime = endTime - startTime; System.out .println("Process all data in " + Util.toTimeHumanReadable(totalTime) + " (" + totalTime + "ms)."); }