List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE
IOFileFilter INSTANCE
To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.
Click Source Link
From source file:org.jts.protocolvalidator.DefinitionFinder.java
/** * Returns a List of Files under the specified path whose name ends with the extension '.xml' or '.jsidl'. * If path refers to a single file, returns a list containing one element-the file referred to by path itself, * if that file's name ends with extension '.xml' or '.jsidl'. *//*from w w w.jav a2s. co m*/ private static List<File> getFileList(File mainFilePath, File path, File schema) { List<File> fileList = new ArrayList<File>(); List<File> tmpFileList = new ArrayList<File>(FileUtils.listFiles(path, new SuffixFileFilter(new String[] { ".xml", ".jsidl" }), TrueFileFilter.INSTANCE)); if (mainFilePath.isDirectory() || path.isFile()) { // input error return null; } fileList.add(mainFilePath); fileList.addAll(getDependencies(mainFilePath, path, schema, tmpFileList)); return fileList; }
From source file:org.jvnet.hudson.plugins.thinbackup.backup.HudsonBackup.java
private List<File> findAllConfigurations(File dir) { Collection<File> listFiles = FileUtils.listFiles(dir, FileFilterUtils.nameFileFilter(CONFIG_XML), TrueFileFilter.INSTANCE); List<File> confs = new ArrayList<File>(); for (File file : listFiles) { confs.add(file.getParentFile()); }/*from w w w. j a v a 2 s . c o m*/ return confs; }
From source file:org.jvnet.hudson.plugins.thinbackup.backup.HudsonBackup.java
private void backupRootFolder(String folderName) throws IOException { backupRootFolder(folderName, TrueFileFilter.INSTANCE); }
From source file:org.jvnet.hudson.plugins.thinbackup.restore.HudsonRestore.java
private void restore(final File toRestore) throws IOException { final IOFileFilter nextBuildNumberFileFilter = FileFilterUtils.nameFileFilter("nextBuildNumber"); IOFileFilter restoreNextBuildNumberFilter; if (restoreNextBuildNumber) { restoreNextBuildNumberFilter = FileFilterUtils.trueFileFilter(); final Collection<File> restore = FileUtils.listFiles(toRestore, nextBuildNumberFileFilter, TrueFileFilter.INSTANCE); final Map<String, Integer> nextBuildNumbers = new HashMap<String, Integer>(); for (final File file : restore) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); nextBuildNumbers.put(file.getParentFile().getName(), Integer.parseInt(reader.readLine())); } finally { if (reader != null) { reader.close();/*from www. j ava 2 s. c om*/ } } } final Collection<File> current = FileUtils.listFiles(hudsonHome, nextBuildNumberFileFilter, TrueFileFilter.INSTANCE); for (final File file : current) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); final int currentBuildNumber = Integer.parseInt(reader.readLine()); final Integer toRestoreNextBuildNumber = nextBuildNumbers.get(file.getParentFile().getName()); if (currentBuildNumber < toRestoreNextBuildNumber) { restoreNextBuildNumber(file, toRestoreNextBuildNumber); } } finally { if (reader != null) { reader.close(); } } } } else { restoreNextBuildNumberFilter = FileFilterUtils.notFileFilter(nextBuildNumberFileFilter); } FileUtils.copyDirectory(toRestore, this.hudsonHome, restoreNextBuildNumberFilter, true); if (restorePlugins) restorePlugins(toRestore); }
From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java
private static void removeResourceFolder(final IResource resource, final boolean removeOriginalRawRes) throws CoreException { final File[] children = resource.getLocation().toFile().listFiles(); if (children != null) { if (children.length == 0 || removeOriginalRawRes) { try { resource.delete(true, new NullProgressMonitor()); } catch (final Exception e) { // FIXME: why?! the problem is elsewhere!! e.printStackTrace();/*from w w w . jav a2s . c om*/ // FIXME: final IOFileFilter lNoDirFilter = FalseFileFilter.INSTANCE; final WildcardFileFilter lFilter = new WildcardFileFilter(new String[] { "*" }); //$NON-NLS-1$ final Collection<File> files = FileUtils.listFiles(resource.getLocation().toFile(), lFilter, lNoDirFilter); for (final File lFile : files) deleteFileOrDirectory(lFile); final IOFileFilter lDirFilter = TrueFileFilter.INSTANCE; final Collection<File> dirs = FileUtils.listFiles(resource.getLocation().toFile(), lFilter, lDirFilter); for (final File lDir : dirs) deleteFileOrDirectory(lDir); } } else { for (int i = 0; i < children.length; i++) { if (!children[i].getName().toLowerCase().contains(ORIGINAL_2D_FILE_NAME)) { try { final IResource resourceChild = ResourceUtilities .findFileFromURL(children[i].toURI().toURL()); if (resourceChild instanceof IFolder) { removeResourceFolder(resourceChild, removeOriginalRawRes); } else { if (resourceChild != null) resourceChild.delete(true, new NullProgressMonitor()); children[i].delete(); } } catch (final MalformedURLException e) { e.printStackTrace(); } } } } } else { resource.delete(true, new NullProgressMonitor()); } }
From source file:org.limy.eclipse.qalab.action.part.CalcCoberturaAction.java
/** * instrument?SNXt@Cdest/classesRs?[?B/*from w w w . j ava2s. c o m*/ * @throws IOException * @throws CoreException */ private void copyAllClassFiles() throws CoreException, IOException { for (IPath path : getEnv().getBinPaths(true)) { String dir = LimyQalabUtils.createFullPath(getJavaProject(), path); FileUtils.copyDirectory(new File(dir), getDestFile("classes")); } Collection<Object> files = FileUtils.listFiles(getDestFile("classes"), new SuffixFileFilter("Test.class"), TrueFileFilter.INSTANCE); for (Object file : files) { ((File) file).delete(); } }
From source file:org.m2latex.mojo.TexFileUtilsImpl.java
public List getLatexMainDocuments(File directory) throws MojoExecutionException { ArrayList mainFiles = new ArrayList(); Collection texFiles = FileUtils.listFiles(directory, FileFilterUtils.suffixFileFilter(".tex"), TrueFileFilter.INSTANCE); for (Iterator iterator = texFiles.iterator(); iterator.hasNext();) { File file = (File) iterator.next(); if (isTexMainFile(file)) { mainFiles.add(file);/*from ww w .j a v a 2 s . c om*/ } } return mainFiles; }
From source file:org.mda.bcb.tcgagsdata.create.Compilation.java
public void process() throws IOException, Exception { TcgaGSData.printWithFlag("Compilation::process - mClinicalDir=" + mClinicalDir); TcgaGSData.printWithFlag("Compilation::process - mInputFiles=" + mInputFiles); TcgaGSData.printWithFlag("Compilation::process - mOutputFile=" + mOutputFile); Collection<File> results = FileUtils.listFiles(new File(mClinicalDir), FileFilterUtils.nameFileFilter(mInputFiles), TrueFileFilter.INSTANCE); ArrayList<String> headers = getHeaders(results); TreeSet<String> patients = new TreeSet<>(); TreeSet<String> lines = new TreeSet<>(); String headerLine = null;// w ww . jav a 2 s . com for (String header : headers) { if (null == headerLine) { headerLine = header; } else { headerLine = headerLine + "\t" + header; } } boolean headersNeeded = true; for (File clinFile : results) { TcgaGSData.printWithFlag("Compilation::process - clinFile=" + clinFile.getAbsolutePath()); try (BufferedReader br = Files.newBufferedReader(Paths.get(clinFile.getAbsolutePath()), Charset.availableCharsets().get("ISO-8859-1"))) { String line = br.readLine(); ArrayList<String> currentHeaders = new ArrayList<>(); currentHeaders.addAll(Arrays.asList(line.split("\t", -1))); for (line = br.readLine(); null != line; line = br.readLine()) { String newLine = null; String[] splitted = line.split("\t", -1); for (String header : headers) { String token = "NA"; int index = currentHeaders.indexOf(header); if (index > -1) { token = splitted[index]; } if (null == newLine) { newLine = token; } else { newLine = newLine + "\t" + token; } } lines.add(newLine); String patient = GSStringUtils.beforeTab(newLine); if (false == patients.add(patient)) { throw new Exception("ERROR - patient duplicated " + patient); } } } } try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(mOutputFile), Charset.availableCharsets().get("ISO-8859-1"))) { bw.write(headerLine); bw.newLine(); for (String line : lines) { bw.write(line); bw.newLine(); } } }
From source file:org.mda.bcb.tcgagsdata.create.Metadata.java
static public String findMetadataFile(File theDir) { File metadataFile = FileUtils .listFiles(theDir, new WildcardFileFilter("metadata*.tsv"), TrueFileFilter.INSTANCE).iterator() .next();// w w w. jav a2 s .c o m return metadataFile.getAbsolutePath(); }
From source file:org.mda.bcb.tcgagsdata.create.ReadPlatform.java
public void readPlatform(String thePlatform) throws IOException, Exception { TcgaGSData.printWithFlag("readPlatform for " + thePlatform + " beginning"); TcgaGSData.printWithFlag("readPlatform can consume excessive amounts of time and memory"); mNumberOfGenes = 0;/*from ww w . j av a 2 s .c om*/ TreeMap<String, Integer> geneMap = null; { ReadPlatform_GeneEq lg = new ReadPlatform_GeneEq(mReadPath); lg.getNamesGenes(thePlatform); mGenes = lg.mGenes; geneMap = TcgaGSData.buildIndexMap(lg.mGenes); mNumberOfGenes = lg.mSize; } mNumberOfSamples = 0; boolean found = false; long start = System.currentTimeMillis(); TreeSet<File> dataFileList = new TreeSet<>(); dataFileList.addAll(FileUtils.listFiles(new File(mReadPath, thePlatform), new WildcardFileFilter("matrix_data_*.tsv"), TrueFileFilter.INSTANCE)); for (File input : dataFileList) { try (BufferedReader br = Files.newBufferedReader(Paths.get(input.getAbsolutePath()), Charset.availableCharsets().get("ISO-8859-1"))) { found = true; TcgaGSData.printWithFlag("readPlatform file=" + input.getAbsolutePath()); // first line samples String line = br.readLine(); TreeMap<String, Integer> sampleMap = TcgaGSData .buildIndexMap(GSStringUtils.afterTab(line).split("\t", -1)); if (0 == mNumberOfSamples) { mSamples = GSStringUtils.afterTab(line).split("\t", -1); mNumberOfSamples = mSamples.length; mGenesBySamplesValues = new double[mNumberOfGenes][mNumberOfSamples]; } else { if (mNumberOfSamples != GSStringUtils.afterTab(line).split("\t", -1).length) { throw new Exception("Expected sample count of " + mNumberOfSamples + " but found different " + input.getAbsolutePath()); } } line = br.readLine(); while (null != line) { String gene = GSStringUtils.beforeTab(line); Integer intIndex = geneMap.get(gene); if (null != intIndex) { int geneIndex = intIndex; double[] valueList = convertToDouble(GSStringUtils.afterTab(line).split("\t", -1)); for (int x = 0; x < valueList.length; x++) { int sampleIndex = sampleMap.get(mSamples[x]); mGenesBySamplesValues[geneIndex][sampleIndex] = valueList[x]; } } else { throw new Exception( "readPlatform for " + thePlatform + " found unexpected 'gene' = " + gene); } line = br.readLine(); } } } long finish = System.currentTimeMillis(); TcgaGSData.printWithFlag( "readPlatform for " + thePlatform + " retrieved in " + ((finish - start) / 1000.0) + " seconds"); if (false == found) { throw new Exception("readPlatform for " + thePlatform + " not found"); } else { TcgaGSData.printWithFlag("write " + thePlatform + " to " + mWriteFile); writeFile(); } }