List of usage examples for org.apache.commons.io.filefilter SuffixFileFilter SuffixFileFilter
public SuffixFileFilter(List suffixes)
From source file:edu.cuny.cat.Game.java
/** * creates multiple market/specialist clients, each an instance of * {@link MarketClient}, based on parameter files in the specified directory * and its subdirectories. Each of these parameter files define a set of * market clients using the specified parameter base. * /*from w ww .j a v a 2s . c om*/ * For example * * <pre> * cat.specialist.optional.dir = params/elites * cat.specialist.optional.base = elites * </pre> * * specifies to look for parameter files in the directory * <code>params/elites</code> and all market clients are configured using the * parameter base <code>elites</code>. * * @throws InstantiationException * @throws IllegalAccessException */ @SuppressWarnings("unchecked") public static Collection<? extends MarketClient> createOptionalMarkets() throws InstantiationException, IllegalAccessException { final Parameter optionalParam = new Parameter(Game.P_CAT).push(Game.P_SPECIALIST).push(Game.P_OPTIONAL); final ParameterDatabase parameters = Galaxy.getInstance().getTyped(Game.P_CAT, ParameterDatabase.class); if (!parameters.exists(optionalParam.push(Game.P_DIR)) && !parameters.exists(optionalParam.push(Game.P_BASE))) { // no optional markets defined Game.logger.info("no optional market defined at " + optionalParam); return null; } final File dir = parameters.getFile(optionalParam.push(Game.P_DIR), null); if ((dir == null) || !dir.exists() || !dir.isDirectory()) { Game.logger.fatal("Directory for optional markets does NOT exist !"); Game.logger.fatal(dir.toString()); Utils.fatalError(); return null; } else { final String optionalBase = parameters.getString(optionalParam.push(Game.P_BASE), null); Game.logger.info("\n"); if (optionalBase == null) { Game.logger.info("No optional markets configured."); Game.logger.info("\n"); return null; } else { Game.logger.info("creating optional markets defined in " + dir + " at " + optionalBase + " ..."); final Collection<MarketClient> marketColl = new ArrayList<MarketClient>(); final Collection<File> files = FileUtils.listFiles(dir, new SuffixFileFilter(".params"), DirectoryFileFilter.INSTANCE); final ParameterDatabase root = new ParameterDatabase(); ParameterDatabase parametersPerFile = null; Collection<? extends MarketClient> marketCollPerFile = null; final Parameter base = new Parameter(optionalBase); for (final File file : files) { try { Game.logger.info("reading " + file.toString()); parametersPerFile = new ParameterDatabase(file); } catch (final FileNotFoundException e) { e.printStackTrace(); continue; } catch (final IOException e) { e.printStackTrace(); continue; } root.addParent(parameters); root.addParent(parametersPerFile); marketCollPerFile = Game.createMarkets(root, base); marketColl.addAll(marketCollPerFile); root.removeParents(); } return marketColl; } } }
From source file:fr.tpt.atlanalyser.examples.ExampleRunner.java
protected File getOutputMM() { return outputMMDir.listFiles((FilenameFilter) new SuffixFileFilter(".ecore"))[0]; }
From source file:fr.tpt.atlanalyser.examples.ExampleRunner.java
protected File getInputMM() { return inputMMDir.listFiles((FilenameFilter) new SuffixFileFilter(".ecore"))[0]; }
From source file:io.blobkeeper.server.BasicOperationTest.java
private void deleteIndexFiles() { java.io.File basePath = new java.io.File(fileConfiguration.getBasePath()); if (!basePath.exists()) { basePath.mkdir();/* ww w. j av a 2s . co m*/ } java.io.File disk1 = getDiskPathByDisk(fileConfiguration, 0); if (!disk1.exists()) { disk1.mkdir(); } java.io.File disk2 = getDiskPathByDisk(fileConfiguration, 1); if (!disk2.exists()) { disk2.mkdir(); } for (int disk : fileListService.getDisks()) { java.io.File diskPath = getDiskPathByDisk(fileConfiguration, disk); for (java.io.File indexFile : diskPath.listFiles((FileFilter) new SuffixFileFilter(".data"))) { indexFile.delete(); } } java.io.File uploadPath = new java.io.File(fileConfiguration.getUploadPath()); if (!uploadPath.exists()) { uploadPath.mkdir(); } }
From source file:com.example.util.FileUtils.java
/** * Finds files within a given directory (and optionally its subdirectories) * which match an array of extensions.// w ww.j av a 2 s . c o m * * @param directory the directory to search in * @param extensions an array of extensions, ex. {"java","xml"}. If this * parameter is {@code null}, all files are returned. * @param recursive if true all subdirectories are searched as well * @return an collection of java.io.File with the matching files */ public static Collection<File> listFiles(File directory, String[] extensions, boolean recursive) { IOFileFilter filter; if (extensions == null) { filter = TrueFileFilter.INSTANCE; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } return listFiles(directory, filter, recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE); }
From source file:com.edgenius.wiki.service.impl.ThemeServiceImpl.java
public void init() throws IOException { //detect if explode skin has /skin/init_flag file. If it has, first package this skin, then copy it {DataRoot}/data/skins/ directory. //For unit test case, explode directory doesn't exist. if (skinExplosionRoot.exists()) { File[] deployDirs = skinExplosionRoot.getFile().listFiles((FileFilter) DirectoryFileFilter.INSTANCE); for (File dir : deployDirs) { File file = new File(dir, "init_flag"); File skinFile = getSkinXML(dir); if (!file.exists() || !skinFile.exists()) { continue; }// w ww .j a v a 2s. c o m //delete init_flag file, don't zip it! To avoid do this process again in same deployment. file.delete(); File tgtFile = new File(skinResourcesRoot.getFile(), dir.getName() + INSTALL_EXT_NAME); if (!tgtFile.exists()) { try { Map<File, String> listToZip = new HashMap<File, String>(); String rootDir = dir.getCanonicalPath(); listToZip.put(dir, rootDir); ZipFileUtil.createZipFile(tgtFile.getCanonicalPath(), listToZip, false); //this ensure this skin will be deploy in next steps. As skin.xml not exist, the zip file will be exploded. skinFile.delete(); } catch (ZipFileUtilException e) { log.error("Pack system initial skin failed" + tgtFile.getCanonicalFile(), e); } } } } //retrieve all zip files under themes and skins, compare its name and version, deploy it if it doesn't install or newer. File[] files = skinResourcesRoot.getFile().listFiles((FileFilter) new SuffixFileFilter(INSTALL_EXT_NAME)); for (File skinFile : files) { try { explodeSkin(skinFile, false); } catch (ThemeInvalidException e) { log.info("Skin skip deploy {}", e.getMessage()); } } files = themeResourcesRoot.getFile().listFiles((FileFilter) new SuffixFileFilter(INSTALL_EXT_NAME)); for (File themeFile : files) { try { explodeTheme(themeFile, false); } catch (ThemeInvalidException e) { log.info("Theme skip deploy {}", e.getMessage()); } } }
From source file:com.mirth.connect.server.controllers.DefaultExtensionController.java
public List<String> getClientLibraries() { List<String> clientLibFilenames = new ArrayList<String>(); File clientLibDir = new File("client-lib"); if (!clientLibDir.exists() || !clientLibDir.isDirectory()) { clientLibDir = new File("build/client-lib"); }/*from w w w .jav a2s .c o m*/ if (clientLibDir.exists() && clientLibDir.isDirectory()) { Collection<File> clientLibs = FileUtils.listFiles(clientLibDir, new SuffixFileFilter(".jar"), FileFilterUtils.falseFileFilter()); for (File clientLib : clientLibs) { clientLibFilenames.add(FilenameUtils.getName(clientLib.getName())); } } else { logger.error("Could not find client-lib directory: " + clientLibDir.getAbsolutePath()); } return clientLibFilenames; }
From source file:net.sourceforge.vulcan.core.support.AbstractFileStore.java
@SuppressWarnings("unchecked") final URL[] getJars(File dir) { final List<URL> list = new ArrayList<URL>(); final Collection<File> jars = FileUtils.listFiles(dir, new SuffixFileFilter(".jar"), null); for (File file : jars) { try {//from w ww . j av a 2s . c om list.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw new RuntimeException(e); } } return list.toArray(new URL[list.size()]); }
From source file:nl.bneijt.javapjson.JavapJsonMojo.java
public void execute() throws MojoExecutionException { JsonFactory jsonFactory = new JsonFactory(); if (!outputDirectory.exists()) { throw new MojoExecutionException( "No build output directory found. Was looking at \"" + outputDirectory + "\""); }// w w w .j a va 2 s. co m String jsonDirectory = buildDirectory.getPath() + File.separator + "javap-json"; File jsonDirectoryFile = new File(jsonDirectory); if (!jsonDirectoryFile.exists()) { if (!jsonDirectoryFile.mkdir()) { throw new MojoExecutionException( "Could not create output directory \"" + jsonDirectoryFile.getPath() + "\""); } getLog().debug("Created output directory \"" + jsonDirectoryFile.getPath() + "\""); } for (File classFile : FileUtils.listFiles(outputDirectory, new SuffixFileFilter(CLASS_EXTENSION), TrueFileFilter.INSTANCE)) { String output = runJavap(classFile); JavapLOutput parseL = JavapParser.parseL(output); File outputFile = new File(jsonDirectory + File.separator + "current.json"); try { JsonGenerator jsonOutput = jsonFactory.createJsonGenerator(outputFile, JsonEncoding.UTF8); parseL.toJsonOnto(jsonOutput); //Move file into correct position File classDirectory = classFile.getParentFile(); String classFileName = classFile.getName(); String restOfDirectory = classDirectory.getPath().substring(outputDirectory.getPath().length()); File jsonOutputFileDirectory = new File(jsonDirectory + restOfDirectory); File jsonOutputFile = new File(jsonOutputFileDirectory.getPath() + File.separator + classFileName.substring(0, classFileName.length() - ".class".length()) + ".json"); if (!jsonOutputFileDirectory.exists()) FileUtils.forceMkdir(jsonOutputFileDirectory); if (jsonOutputFile.exists()) { FileUtils.deleteQuietly(jsonOutputFile); } FileUtils.moveFile(outputFile, jsonOutputFile); } catch (IOException e) { // TODO Auto-generated catch block throw new MojoExecutionException("Unable to serialize javap output to Json", e); } } }
From source file:nl.strohalm.cyclos.http.lifecycle.CustomizedFileInitialization.java
public void init(final ServletContext context) { // First, clear the customized css files to ensure proper migration from previous versions when css files were not customized final File customizedStylesDir = new File( context.getRealPath(CustomizationHelper.customizedPathFor(context, CustomizedFile.Type.STYLE))); for (final File css : customizedStylesDir.listFiles((FilenameFilter) new SuffixFileFilter(".css"))) { css.delete();//from www . ja va2 s .co m } final LocalSettings localSettings = SettingsHelper.getLocalSettings(context); final CustomizedFileQuery query = new CustomizedFileQuery(); query.fetch(CustomizedFile.Relationships.GROUP); query.setAll(true); final List<CustomizedFile> files = customizedFileService.search(query); for (final CustomizedFile customizedFile : files) { final CustomizedFile.Type type = customizedFile.getType(); final String name = customizedFile.getName(); final File physicalFile = CustomizationHelper.customizedFileOf(context, customizedFile); final File originalFile = CustomizationHelper.originalFileOf(context, type, name); try { // No conflicts are checked for style sheet files if (type != CustomizedFile.Type.STYLE) { final boolean wasConflict = customizedFile.isConflict(); // Check if the file contents has changed since the customization String originalFileContents = null; if (originalFile.exists()) { originalFileContents = FileUtils.readFileToString(originalFile); if (originalFileContents.length() == 0) { originalFileContents = null; } } // Check if the file is now on conflict (or the new contents has changed) boolean contentsChanged; boolean newContentsChanged; if (type == CustomizedFile.Type.APPLICATION_PAGE) { contentsChanged = !StringUtils.trimToEmpty(originalFileContents) .equals(StringUtils.trimToEmpty(customizedFile.getOriginalContents())) && !StringUtils.trimToEmpty(originalFileContents) .equals(StringUtils.trimToEmpty(customizedFile.getContents())); newContentsChanged = contentsChanged && !StringUtils.trimToEmpty(originalFileContents) .equals(StringUtils.trimToEmpty(customizedFile.getNewContents())); } else { contentsChanged = !StringUtils.trimToEmpty(originalFileContents) .equals(StringUtils.trimToEmpty(customizedFile.getOriginalContents())); newContentsChanged = !StringUtils.trimToEmpty(originalFileContents) .equals(StringUtils.trimToEmpty(customizedFile.getNewContents())); } if (!wasConflict && contentsChanged) { // Save the new contents, marking the file as conflicts customizedFile.setNewContents(originalFileContents); customizedFileService.save(customizedFile); // Generate an alert if the file is customized for the whole system if (customizedFile.getGroup() == null && customizedFile.getGroupFilter() == null) { SystemAlert.Alerts alertType = null; switch (type) { case APPLICATION_PAGE: alertType = SystemAlert.Alerts.NEW_VERSION_OF_APPLICATION_PAGE; break; case HELP: alertType = SystemAlert.Alerts.NEW_VERSION_OF_HELP_FILE; break; case STATIC_FILE: alertType = SystemAlert.Alerts.NEW_VERSION_OF_STATIC_FILE; break; } alertService.create(alertType, customizedFile.getName()); } } else if (wasConflict && newContentsChanged) { // The file has changed again. Update the new contents customizedFile.setNewContents(originalFileContents); customizedFileService.save(customizedFile); } } // Check if we must update an style file final long lastModified = customizedFile.getLastModified() == null ? System.currentTimeMillis() : customizedFile.getLastModified().getTimeInMillis(); if (!physicalFile.exists() || physicalFile.lastModified() != lastModified) { physicalFile.getParentFile().mkdirs(); FileUtils.writeStringToFile(physicalFile, customizedFile.getContents(), localSettings.getCharset()); physicalFile.setLastModified(lastModified); } } catch (final IOException e) { LOG.warn("Error handling customized file: " + physicalFile.getAbsolutePath(), e); } } // We must copy all non-customized style sheets to the customized dir, so there will be no problems for locating images final File originalDir = new File( context.getRealPath(CustomizationHelper.originalPathFor(context, CustomizedFile.Type.STYLE))); for (final File original : originalDir.listFiles()) { final File customized = new File(customizedStylesDir, original.getName()); if (!customized.exists()) { try { FileUtils.copyFile(original, customized); } catch (final IOException e) { LOG.warn("Error copying style sheet file: " + customized.getAbsolutePath(), e); } } } }