List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:org.wisdom.test.internals.RunnerUtils.java
/** * Checks if a file having somewhat the current tested application name is contained in the given directory. This * method follows the default maven semantic. The final file is expected to have a name compliant with the * following rules: <code>artifactId-version.jar</code>. If the version ends with <code>-SNAPSHOT</code>, * it just checks for <code>artifactId-stripped_version</code>, where stripped version is the version without the * <code>SNAPSHOT</code> part. * <p>/* www .j av a 2 s . com*/ * The artifactId and version are read from the <code>target/osgi/osgi.properties</code> file, * that should have been written by the Wisdom build process. * * @param directory the directory * @return the bundle file if found * @throws java.io.IOException if something bad happens. */ public static File detectApplicationBundleIfExist(File directory) throws IOException { Properties properties = getMavenProperties(); if (properties == null || directory == null || !directory.isDirectory()) { return null; } final String artifactId = properties.getProperty("project.artifactId"); final String groupId = properties.getProperty("project.groupId"); final String bsn = getBundleSymbolicName(groupId, artifactId); String version = properties.getProperty("project.version"); final String strippedVersion; if (version.endsWith("-SNAPSHOT")) { strippedVersion = version.substring(0, version.length() - "-SNAPSHOT".length()); } else { strippedVersion = version; } Iterator<File> files = FileUtils.iterateFiles(directory, new AbstractFileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().startsWith(bsn + "-" + strippedVersion) && file.getName().endsWith(".jar"); } }, TrueFileFilter.INSTANCE); if (files.hasNext()) { return files.next(); } return null; }
From source file:pl.psnc.synat.wrdz.zmkd.plan.execution.PlanExecutionManagerBean.java
/** * Retrieves from execution outcome the data files infos. The remaining outcomes are omitted, since file * transformation is limited to chains of services that returns files always. * // w w w . j a va 2 s .c o m * @param execOutcome * execution outcome * @param servOutcomeInfos * list of validated service outcome infos * @param outputFileFormat * supposed output format * @param srcFileInfo * info about source file * @param workDir * working directory * @return info about destination files * @throws InvalidHttpResponseException * when content of the response cannot be retrieved * @throws UnexpectedHttpResponseException * when no data file can be retrieved * @throws ZipArchivingException * when ZIP archiving failed */ private List<DataFileInfo> retrieveDataFilesFromOutcome(ExecutionOutcome execOutcome, List<ServiceOutcomeInfo> servOutcomeInfos, FileFormat outputFileFormat, DataFileInfo srcFileInfo, File workDir) throws InvalidHttpResponseException, UnexpectedHttpResponseException, ZipArchivingException { if (validateTransfromationOutcome(servOutcomeInfos) == null) { throw new UnexpectedHttpResponseException( "No description of the service matches to the supposed transformation outcome", execOutcome.getStatusCode(), execOutcome.getContentType()); } List<DataFileInfo> destFileInfos = new ArrayList<DataFileInfo>(); if (execOutcome.getContentType().startsWith("application/zip")) { File destDir = new File(workDir, uuidGenerator.generateCacheFolderName()); destDir.mkdir(); try { ZipUtility.unzip(execOutcome.getContent(), destDir); } catch (IOException e) { throw new ZipArchivingException(e); } Iterator<File> it = FileUtils.iterateFiles(destDir, null, true); String base = FilenameUtils.getBaseName(srcFileInfo.getPath()); int inc = 0; while (it.hasNext()) { Integer sequence = srcFileInfo.getSequence(); if (sequence != null) { sequence += inc; } inc++; String path = base + inc + "." + outputFileFormat.getExtension(); DataFileInfo destFileInfo = new DataFileInfo(path, outputFileFormat.getPuid(), sequence, it.next()); destFileInfos.add(destFileInfo); } } else { String path = FilenameUtils.getBaseName(srcFileInfo.getPath()) + "." + outputFileFormat.getExtension(); File destFile = new File(workDir, uuidGenerator.generateRandomFileName()); try { saveContentIntoFile(execOutcome, destFile); } catch (IOException e) { throw new InvalidHttpResponseException("Error retrieving the content", e); } DataFileInfo destFileInfo = new DataFileInfo(path, outputFileFormat.getPuid(), srcFileInfo.getSequence(), destFile); destFileInfos.add(destFileInfo); } return destFileInfos; }
From source file:plugin.FacetDefinitionTest.java
/** * Verify that all non-excluded java files are represented by an entry * in the applicationContext file. An exceptions list is used to track * classes which are not facets./*from ww w . j a v a 2 s. c o m*/ * * @param sourceFolder The folder containing the source files. * @throws IOException */ private void checkFacetsDefined(File sourceFolder) throws IOException { assertTrue("Source folder " + sourceFolder.getAbsolutePath() + " should be a directory", sourceFolder.isDirectory()); String packageName = sourceFolder.getPath().replace(File.separatorChar, '.').replace("code.src.java.", ""); String contextData = FileUtils.readFileToString(new File(APP_CONTEXT_FILE), "UTF-8"); for (Iterator<File> facetSourceFileIter = FileUtils.iterateFiles(sourceFolder, new String[] { "java" }, false); facetSourceFileIter.hasNext();) { File srcFile = facetSourceFileIter.next(); String testString = srcFile.getName(); testString = testString.replaceAll(".java", ""); if (exceptions.contains(testString)) { //System.out.println("Skipping " + srcFile); continue; } testString = "class=\"" + packageName + "." + testString + "\""; assertTrue("Unable to find Spring definition for " + srcFile, contextData.indexOf(testString) >= 0); } }
From source file:rapture.repo.file.FileDataStore.java
@Override public void visitKeys(String prefix, StoreKeyVisitor iStoreKeyVisitor) { File dir = FileRepoUtils.makeGenericFile(parentDir, convertKeyToPath(prefix)); if (!dir.exists()) { try {/*from w w w . ja va 2 s . c om*/ File file = FileRepoUtils.makeGenericFile(parentDir, convertKeyToPath(prefix) + EXTENSION); if (file.exists()) { iStoreKeyVisitor.visit(prefix + removeExtension(file.getName()), FileUtils.readFileToString(file)); } } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Could not read keys", e); } return; } Iterator<File> fIterator = FileUtils.iterateFiles(dir, null, true); while (fIterator.hasNext()) { File f = fIterator.next(); if (f.isFile()) { try { if (!iStoreKeyVisitor.visit(prefix + removeExtension(f.getName()), FileUtils.readFileToString(f))) break; } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Could not read keys", e); } } } }
From source file:rapture.repo.file.FileDataStore.java
@Override public void visitKeysFromStart(String startPoint, StoreKeyVisitor iStoreKeyVisitor) { File dir = FileRepoUtils.makeGenericFile(parentDir, convertKeyToPath("")); if (!dir.exists()) { return;/*from w ww .ja v a 2s. c om*/ } int authLen = dir.getPath().toString().length(); boolean canStart = startPoint == null; Iterator<File> fIterator = FileUtils.iterateFiles(dir, null, true); while (fIterator.hasNext()) { File f = fIterator.next(); if (f.isFile()) { try { if (!canStart) { if (f.getName().equals(startPoint)) { canStart = true; // On the next loop } } else { // Skip the prefix and authority String fileName = f.getPath().toString(); String docPath = fileName.substring(authLen + 1); if (docPath.endsWith(".txt")) docPath = docPath.substring(0, docPath.length() - 4); if (!iStoreKeyVisitor.visit(docPath, FileUtils.readFileToString(f))) break; } } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Could not read keys", e); } } } }
From source file:sernet.gs.service.AbstractReportTemplateService.java
@SuppressWarnings("unchecked") public Iterator<File> listPropertiesFiles(String fileName) { String baseName = removeSuffix(fileName); IOFileFilter filter = new RegexFileFilter(baseName + "\\_?.*\\.properties", IOCase.INSENSITIVE); Iterator<File> iter = FileUtils.iterateFiles(new File(getTemplateDirectory()), filter, null); return iter;//from w ww.j a v a 2s . c om }
From source file:sernet.gs.service.AbstractReportTemplateService.java
@SuppressWarnings({ "unchecked" }) public String[] getReportTemplateFileNames() { List<String> list = new ArrayList<String>(); IOFileFilter filter = new SuffixFileFilter("rptdesign", IOCase.INSENSITIVE); Iterator<File> iter = FileUtils.iterateFiles(new File(getTemplateDirectory()), filter, null); while (iter.hasNext()) { list.add(iter.next().getAbsolutePath()); }//from w ww . ja va 2 s . c om return list.toArray(new String[list.size()]); }
From source file:sernet.gs.service.AbstractReportTemplateService.java
@SuppressWarnings("unchecked") private String[] getServerRptDesigns() throws ReportTemplateServiceException { List<String> list = new ArrayList<String>(0); // // DirFilter = null means no subdirectories IOFileFilter filter = new SuffixFileFilter("rptdesign", IOCase.INSENSITIVE); Iterator<File> iter = FileUtils.iterateFiles(new File(getTemplateDirectory()), filter, null); while (iter.hasNext()) { list.add(iter.next().getAbsolutePath()); }/*from w ww . j a va 2 s . c om*/ return list.toArray(new String[list.size()]); }
From source file:sernet.verinice.service.DummyReportDepositService.java
@SuppressWarnings("unchecked") private String[] getServerRptDesigns() { List<String> list = new ArrayList<String>(0); // // DirFilter = null means no subdirectories IOFileFilter filter = new SuffixFileFilter("rptdesign", IOCase.INSENSITIVE); Iterator<File> iter = FileUtils.iterateFiles(new File(getReportDepositPath()), filter, null); while (iter.hasNext()) { list.add(iter.next().getAbsolutePath()); }/* w w w . ja v a 2 s.c o m*/ return list.toArray(new String[list.size()]); }
From source file:sernet.verinice.service.test.ReportDepositTest.java
private Iterator<File> listPropertiesFiles(String fileName, String dir) { String baseName = removeSuffix(fileName); IOFileFilter filter = new RegexFileFilter(baseName + "\\_?.*\\.properties", IOCase.INSENSITIVE); Iterator<File> iter = FileUtils.iterateFiles(new File(dir), filter, null); return iter;/* www .j a v a 2 s . co m*/ }