List of usage examples for org.apache.commons.io.filefilter NameFileFilter NameFileFilter
public NameFileFilter(List names)
From source file:com.przyjaznyplan.utils.CsvConverter.java
private void ifTextGetIt(String value, ContentValues sqlValues) { if (value != null && value.endsWith(TXT_EXT)) { Collection files = FileUtils.listFiles(new File(rootFolder), new NameFileFilter(value), TrueFileFilter.INSTANCE); Iterator<File> iterator = files.iterator(); if (iterator.hasNext()) { File f = iterator.next(); List<String> linesOfText = null; try { linesOfText = FileUtils.readLines(f); } catch (IOException e) { Log.e("File IO", e.getMessage()); }/*w ww .j av a 2 s . c o m*/ StringBuilder builder = new StringBuilder(); if (linesOfText != null) { for (String line : linesOfText) { builder.append(line); } } sqlValues.put(Czynnosc.TEXT, builder.toString()); } } else if (value != null && value.length() > 0) { sqlValues.put(Czynnosc.TEXT, value); } }
From source file:it.cnr.isti.thematrix.mapping.utils.TempFileManager.java
/** * Return the path of a file. /*from w ww. j a va2 s .c o m*/ * First checks presence in IAD directory, if not return results as path for the file. * It expects a file in the format of filename.extension. * @param filename * @return the path of a file */ // FIXME: this method should be moved elsewhere public static File getPathForFile(String filename) { File iad = new File(Dynamic.getIadPath()); File result = new File(Dynamic.getResultsPath()); String[] iad_list = iad.list(new NameFileFilter(filename)); String[] result_list = result.list(new NameFileFilter(filename)); if (iad_list.length > 0 && result_list.length > 0) LogST.logP(0, "*** WARNING: found the file " + filename + " both in IAD and RESULTs. Now reading from RESULTS."); if (result_list.length > 0) return result; else if (iad_list.length > 0) return iad; else return result; }
From source file:com.mirth.connect.server.ExtensionLoader.java
/** * Loads the metadata files (plugin.xml, source.xml, destination.xml) for all extensions of the * specified type. If this function fails to parse the metadata file for an extension, it will * skip it and continue.//from w w w. ja v a2s. c o m */ private synchronized void loadExtensions() { if (!loadedExtensions) { try { // match all of the file names for the extension IOFileFilter nameFileFilter = new NameFileFilter( new String[] { "plugin.xml", "source.xml", "destination.xml" }); // this is probably not needed, but we dont want to pick up directories, // so we AND the two filters IOFileFilter andFileFilter = new AndFileFilter(nameFileFilter, FileFilterUtils.fileFileFilter()); // this is directory where extensions are located File extensionPath = new File(getExtensionsPath()); // do a recursive scan for extension files Collection<File> extensionFiles = FileUtils.listFiles(extensionPath, andFileFilter, FileFilterUtils.trueFileFilter()); for (File extensionFile : extensionFiles) { try { MetaData metaData = (MetaData) serializer .deserialize(FileUtils.readFileToString(extensionFile), MetaData.class); if (isExtensionCompatible(metaData)) { if (metaData instanceof ConnectorMetaData) { ConnectorMetaData connectorMetaData = (ConnectorMetaData) metaData; connectorMetaDataMap.put(connectorMetaData.getName(), connectorMetaData); if (StringUtils.contains(connectorMetaData.getProtocol(), ":")) { for (String protocol : connectorMetaData.getProtocol().split(":")) { connectorProtocolsMap.put(protocol, connectorMetaData); } } else { connectorProtocolsMap.put(connectorMetaData.getProtocol(), connectorMetaData); } } else if (metaData instanceof PluginMetaData) { pluginMetaDataMap.put(metaData.getName(), (PluginMetaData) metaData); } } else { logger.error("Extension \"" + metaData.getName() + "\" is not compatible with this version of Mirth Connect and was not loaded. Please install a compatible version."); invalidMetaDataMap.put(metaData.getName(), metaData); } } catch (Exception e) { logger.error("Error reading or parsing extension metadata file: " + extensionFile.getName(), e); } } } catch (Exception e) { logger.error("Error loading extension metadata.", e); } finally { loadedExtensions = true; } } }
From source file:com.thoughtworks.go.server.presentation.models.JobDetailPresentationModel.java
public String getIndexPageURL() { try {/*from w ww . j av a2 s . c o m*/ File testOutputFolder = artifactsService.findArtifact(job.getIdentifier(), TEST_OUTPUT_FOLDER); if (testOutputFolder.exists()) { Collection<File> files = FileUtils.listFiles(testOutputFolder, new NameFileFilter("index.html"), TrueFileFilter.TRUE); if (files.isEmpty()) { return null; } File testIndexPage = files.iterator().next(); return getRestfulUrl( testIndexPage.getPath().substring(testIndexPage.getPath().indexOf(TEST_OUTPUT_FOLDER))); } } catch (Exception ignore) { } return null; }
From source file:ch.unibas.fittingwizard.infrastructure.RealVmdDisplayScript.java
private File getVdwFileForMolecule(MoleculeId moleculeId) { String vdwFileName = moleculeId.getName() + RealMultipoleGaussScript.vdwExtension; Collection<File> files = FileUtils.listFiles(moleculesDir, new NameFileFilter(vdwFileName), TrueFileFilter.TRUE);/* w w w . j a v a 2 s . c om*/ if (files.size() != 1) { throw new RuntimeException(String.format("No or too many %s files found in %s.", vdwFileName, moleculesDir.getAbsolutePath())); } File vdwFile = files.iterator().next(); return vdwFile; }
From source file:com.ibm.liberty.starter.service.swagger.api.v1.ProviderEndpoint.java
@GET @Path("packages/prepare") @Produces(MediaType.TEXT_PLAIN)//from www .j av a2s . co m public String prepareDynamicPackages(@QueryParam("path") String techWorkspaceDir, @QueryParam("options") String options, @QueryParam("techs") String techs) throws IOException { if (techWorkspaceDir != null && !techWorkspaceDir.trim().isEmpty()) { File packageDir = new File(techWorkspaceDir + "/package"); if (packageDir.exists() && packageDir.isDirectory()) { FileUtils.deleteDirectory(packageDir); log.finer("Deleted package directory : " + techWorkspaceDir + "/package"); } if (options != null && !options.trim().isEmpty()) { String[] techOptions = options.split(","); String codeGenType = techOptions.length >= 1 ? techOptions[0] : null; if ("server".equals(codeGenType)) { String codeGenSrcDirPath = techWorkspaceDir + "/" + codeGenType + "/src"; File codeGenSrcDir = new File(codeGenSrcDirPath); if (codeGenSrcDir.exists() && codeGenSrcDir.isDirectory()) { String packageSrcDirPath = techWorkspaceDir + "/package/src"; File packageSrcDir = new File(packageSrcDirPath); FileUtils.copyDirectory(codeGenSrcDir, packageSrcDir, FileFilterUtils.notFileFilter(new NameFileFilter( new String[] { "RestApplication.java", "AndroidManifest.xml" }))); log.fine("Copied files from " + codeGenSrcDirPath + " to " + packageSrcDirPath); } else { log.fine("Swagger code gen source directory doesn't exist : " + codeGenSrcDirPath); } } else { log.fine("Invalid options : " + options); return "Invalid options : " + options; } } if (techs != null && !techs.trim().isEmpty()) { //Perform actions based on other technologies/micro-services that were selected by the user String[] techList = techs.split(","); boolean restEnabled = false; boolean servletEnabled = false; for (String tech : techList) { switch (tech) { case "rest": restEnabled = true; break; case "web": servletEnabled = true; break; } } log.finer("Enabled : REST=" + restEnabled + " : Servlet=" + servletEnabled); if (restEnabled) { // Swagger and REST are selected. Add Swagger annotations to the REST sample application. String restSampleAppPath = getSharedResourceDir() + "appAccelerator/swagger/samples/rest/LibertyRestEndpoint.java"; File restSampleApp = new File(restSampleAppPath); if (restSampleApp.exists()) { String targetRestSampleFile = techWorkspaceDir + "/package/src/main/java/application/rest/LibertyRestEndpoint.java"; FileUtils.copyFile(restSampleApp, new File(targetRestSampleFile)); log.finer("Successfuly copied " + restSampleAppPath + " to " + targetRestSampleFile); } else { log.fine("No swagger annotations were added : " + restSampleApp.getAbsolutePath() + " : exists=" + restSampleApp.exists()); } } if (servletEnabled) { //Swagger and Servlet are selected. Add swagger.json stub that describes the servlet endpoint to META-INF/stub directory. String swaggerStubPath = getSharedResourceDir() + "appAccelerator/swagger/samples/servlet/swagger.json"; File swaggerStub = new File(swaggerStubPath); if (swaggerStub.exists()) { String targetStubPath = techWorkspaceDir + "/package/src/main/webapp/META-INF/stub/swagger.json"; FileUtils.copyFile(swaggerStub, new File(targetStubPath)); log.finer("Successfuly copied " + swaggerStubPath + " to " + targetStubPath); } else { log.fine("Didn't add swagger.json stub : " + swaggerStub.getAbsolutePath() + " : exists=" + swaggerStub.exists()); } } } } else { log.fine("Invalid path : " + techWorkspaceDir); return "Invalid path"; } return "success"; }
From source file:ch.unibas.fittingwizard.infrastructure.RealVmdDisplayScript.java
private File getCubeFileForMolecule(MoleculeId moleculeId) { String cubeFileName = moleculeId.getName() + RealMultipoleGaussScript.cubeExtension; Collection<File> files = FileUtils.listFiles(moleculesDir, new NameFileFilter(cubeFileName), TrueFileFilter.TRUE);//w w w . ja v a 2 s . c om if (files.size() != 1) { throw new RuntimeException(String.format("No or too many %s files found in %s.", cubeFileName, moleculesDir.getAbsolutePath())); } File cubeFile = files.iterator().next(); return cubeFile; }
From source file:bioLockJ.module.classifier.r16s.QiimeClassifier.java
/** * Subclasses call this method to input files to only those named OTU_TABLE in dir (and its subdirs). *//*from w w w.java 2 s .co m*/ @Override protected void initInputFiles(final File dir) throws Exception { Log.out.info("Get input files from " + getDirName(dir) + " named: " + OTU_TABLE); final IOFileFilter ff = new NameFileFilter(OTU_TABLE); setModuleInput(dir, ff, TrueFileFilter.INSTANCE); }
From source file:com.thoughtworks.go.server.service.BackupServiceH2IntegrationTest.java
private File backedUpFile(final String filename) { return new ArrayList<>( FileUtils.listFiles(backupsDirectory, new NameFileFilter(filename), TrueFileFilter.TRUE)).get(0); }
From source file:com.tasktop.c2c.server.internal.profile.service.template.GitServiceCloner.java
/** * @param directory// www . jav a2 s . com * @param context * @throws IOException */ private void maybeRewriteRepo(File directory, CloneContext context) throws IOException { if (context.getProjectTemplateMetadata() == null || context.getProjectTemplateMetadata().getFileReplacements() == null) { return; } for (GitFileReplacement fileReplacement : context.getProjectTemplateMetadata().getFileReplacements()) { ProjectTemplateProperty property = context.getProperty(fileReplacement.getPropertyId()); if (property == null || property.getValue() == null) { throw new IllegalStateException("Missing property: " + fileReplacement.getPropertyId()); } IOFileFilter fileFilter; if (fileReplacement.getFileName() != null) { fileFilter = new NameFileFilter(fileReplacement.getFileName()); } else if (fileReplacement.getFilePattern() != null) { fileFilter = new RegexFileFilter(fileReplacement.getFilePattern()); } else { fileFilter = TrueFileFilter.INSTANCE; } IOFileFilter dirFilter = new NotFileFilter(new NameFileFilter(".git")); for (File file : FileUtils.listFiles(directory, fileFilter, dirFilter)) { // REVIEW, this rewrites the content, by streaming the entire process into memory. String content = FileUtils.readFileToString(file); String rewrittenContent = content.replace(fileReplacement.getPatternToReplace(), property.getValue()); FileUtils.write(file, rewrittenContent); } } }