Util method that allow to scan all files in a folder. Works in cooperation with {@link #setFileFilter(FileFilter)} or
{@link #setFileExtensionToFilter(String...)}

@param directoryToScan
@return
188211
public ArrayList<File> scanAllFiles(File directoryToScan) {
		CumulativeFileScannerObserver fileScanner = new CumulativeFileScannerObserver();
		
		DirectoryScanner directoryScanner = new DirectoryScanner(fileScanner);
		for (FileScannerObserver fileScannerObserver : fileScanners) {
			directoryScanner.addFileScanner(fileScannerObserver);
		}
		directoryScanner.setFileFilter(this.fileFilter);
		directoryScanner.scanDirectory(directoryToScan);
		return fileScanner.getResults();
	}
357717
public static File [] getFilesWithPrefix(File dir, final String prefix) {
        FileFilter prefixFilter = new FileFilter() {
                public boolean accept(File pathname)
                {
                    return pathname.getName().toLowerCase().
                        startsWith(prefix.toLowerCase());
                }
            };
        return dir.listFiles(prefixFilter);
    }
458241
public FileScanner setSearchTypes(String... srTypes) {
        if (srTypes == null || srTypes.length == 0) {
            this.srTypes = new String[0];
        } else {
            this.srTypes = srTypes;
        }
        return this;
    }
1240691
public List<File> scan(Resource resource) {
        Scanner scanner = buildContext.newScanner(new File(resource.getDirectory()), true);
        setupScanner(scanner, resource);
        scanner.scan();
        List<File> files = new ArrayList<File>();
        for (String file : scanner.getIncludedFiles()) {
            files.add(new File(resource.getDirectory(), file));
        }
        return files;
    }
575432
public static File[] getDescriptorFiles( File definitionDir , final String prefix , final String suffix )
    {
        return definitionDir.listFiles(new FileFilter() {
            /*
             * (non-Javadoc)
             * @see java.io.FileFilter#accept(java.io.File)
             */
            @Override
			public boolean accept(File pathname)
            {
                if (!pathname.isFile() || !pathname.canRead())
                    return false;
                
                String name = pathname.getName();
                return name.toLowerCase().endsWith(suffix) && name.startsWith(prefix);
            }
        });
    }
470618
public static boolean fileMkDirs(final File target) {
        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            @Override
            public Boolean run() {
                return target.mkdirs();
            }

        });
    }
677663
public final synchronized void findFiles(File directory, FileFilter filter, Collection<? super File> fileOut) {
		if (directory != null && filter != null) {
			File candidate;
			final List<File> candidates = new ArrayList<>();

			final String relativePath = removePathPrefix(getBaseDirectory(), directory);

			getLog().debug("Retreiving " //$NON-NLS-1$
					+ filter.toString() + " files from " //$NON-NLS-1$
					+ relativePath);

			candidates.add(directory);
			int nbFiles = 0;

			while (!candidates.isEmpty()) {
				candidate = candidates.remove(0);
				if (candidate.isDirectory()) {
					final File[] children = candidate.listFiles(filter);
					if (children != null) {
						for (final File child : children) {
							if (child != null && child.isDirectory()) {
								candidates.add(child);
							} else {
								fileOut.add(child);
								++nbFiles;
							}
						}
					}
				}
			}

			getLog().debug("Found " //$NON-NLS-1$
					+ nbFiles + " file(s)"); //$NON-NLS-1$
		}
	}
1182136
public boolean containsDirectoryOfType(Class<? extends Directory> type)
    {
        for (Directory dir : _directories) {
            if (type.isAssignableFrom(dir.getClass()))
                return true;
        }
        return false;
    }
890733
public static void finalizeScanCollection(IScanCollection scans) throws FileParsingException {
    // check if there is more than one MS level, otherwise there are no relationships to set up
    if (scans.getMapMsLevel2index().size() < 2) {
      return;
    }
    int msLevelLo = scans.getMapMsLevel2index().firstKey();
    int msLevelHi = scans.getMapMsLevel2index().lastKey();
    int scanNumLo = scans.getMapNum2scan().firstKey();
    int scanNumHi = scans.getMapNum2scan().lastKey();
    Set<Map.Entry<Integer, ScanIndex>> entries = scans.getMapMsLevel2index().entrySet();

    Set<Integer> msLevels = scans.getMapMsLevel2index().keySet();
    Integer[] msLevelsArr = msLevels.toArray(new Integer[msLevels.size()]);
    Arrays.sort(msLevelsArr);

    for (int i = 0; i < msLevelsArr.length - 1; i++) {
      // if we're at the bottom MS level, these Scans can't have children, stop processing,
      // hence i < msLevelsArr.length - 1 in the for loop
      int msLevel = msLevelsArr[i];
      int msLevelNext = msLevelsArr[i + 1];
      TreeMap<Integer, IScan> num2scan = scans.getMapMsLevel2index().get(msLevel).getNum2scan();
      for (Map.Entry<Integer, IScan> kv : num2scan.entrySet()) {
        int curScanNum = kv.getKey();
        IScan curScan = kv.getValue();
        IScan nextScan = scans.getNextScanAtSameMsLevel(curScan);
        Integer nextScanNumGuess = null;
        if (nextScan != null) {
          nextScanNumGuess = nextScan.getNum();
        } else {
          int lastScanNumAtNextMsLevel = scans.getMapMsLevel2index().get(msLevelNext).getNum2scan()
              .lastKey();
            if (lastScanNumAtNextMsLevel > curScanNum) {
                nextScanNumGuess = lastScanNumAtNextMsLevel;
            }
        }
        if (nextScanNumGuess == null) {
          continue;
        }
        NavigableMap<Integer, IScan> childScansGuess =
            scans.getScansByNumSpanAtMsLevel(curScanNum, nextScanNumGuess, msLevelNext);
        if (childScansGuess == null) {
          // there were no children found for this parent scan, so just leave it as is
          // with NULL instead of children List
          continue;
        } else {
          curScan.setChildScans(new ArrayList<Integer>(childScansGuess.size()));
        }
        for (Map.Entry<Integer, IScan> childNum2scan : childScansGuess.entrySet()) {
          int childNum = childNum2scan.getKey();
          IScan childScan = childNum2scan.getValue();
          curScan.getChildScans().add(childScan.getNum());
          PrecursorInfo precursor = childScan.getPrecursor();
          if (precursor != null) {

            Integer thisMsLevel = curScan.getMsLevel();
            Integer chldMsLevel = childScan.getMsLevel();
            if (precursor.getParentScanNum() == null && thisMsLevel != null && chldMsLevel != null
                && thisMsLevel + 1 == chldMsLevel) {

              Double pLo = precursor.getMzRangeStart();
              Double pHi = precursor.getMzRangeEnd();
              Double sLo = curScan.getScanMzWindowLower();
              Double sHi = curScan.getScanMzWindowUpper();
              if (pLo != null && pHi != null && sLo != null && sHi != null) {
                // if we know precursor isolation window and the scan's m/z scan range
                // they must overlap
                if (pLo <= sHi && sLo <= pHi) {
                  // they overlap!
                  if (pLo.equals(pHi)) { // it's a single point
                    precursor.setParentScanNum(curScanNum);
                  } else {
                    final double minOverlap = 0.75;
                    double overlap = Math.min(pHi, sHi) - Math.max(pLo, sLo);
                    precursor.setParentScanNum(curScanNum);
                  }
                }

              } else {
                // otherwise blindly add it
                precursor.setParentScanNum(curScanNum);
              }
            }

            // this else condition seems to not hold when some scans were cut out from mzXML file with ProteoWizrd.
            // E.g. when only MS2 scans are kept and all MS1 scans were removed, then the precursor info still
            // has that link to MS1 scan, but the scan itself is not in the file, thus the inferred value is incorrect.
//                        else {
//                            // well this is weird, should never happen:
//                            // the Scan contained PrecursorInfo, but the number was different from the inferred one:
//                            // inference is done by selecting the first MS1 scan that is BEFORE this MSn scan
//                            throw new FileParsingException(String.format("When trying to set parent for Scan #%d, "+
//                                    "the Scan contained PrecursorInfo, but the number was different from the inferred one.\n", childNum));
//                        }

          } else {
            // this should never happen, precursorInfo should be parsed from mzXML in the first place
            throw new FileParsingException(
                String.format("When trying to set parent for Scan #%d, " +
                        "the precursor (PrecursorInfo) field was null, which should not happen.\n",
                    childNum));
          }
        }
      }
    }
  }
1302423
public boolean directoryContainsFiles(File fileDir)
    {
        boolean containsFiles = false;
        File[] files = fileDir.listFiles();
        if (files != null)
        {
            for (File file : files)
            {
                if (!file.isDirectory())
                    containsFiles = true;
            }
        }
        return containsFiles;
    }
113709
private void createFileFilter()
	{
		HashMap<String, String[]> extensionMap = MultimediaContainerManager.getSupportedFileExtensionsPerContainer();
		
		ArrayList<FileFilter> chooserFilterArray = new ArrayList<FileFilter>(extensionMap.size() + 1);

		// add all single file extensions grouped by container
		Set<String> containerNameSet = extensionMap.keySet();
		Iterator<String> containerNameIterator = containerNameSet.iterator();
		while (containerNameIterator.hasNext())
		{
			String containerName = containerNameIterator.next();
			String [] extensions = extensionMap.get(containerName);
			StringBuilder fileText = new StringBuilder(containerName);
			fileText.append(" (");
			int ende = extensions.length-1;
			for (int i=0; i<=ende; i++)
			{
				fileText.append("*.").append(extensions[i]);
				if (i<ende) fileText.append(", ");
			}
			fileText.append(')');
			chooserFilterArray.add(new FileChooserFilter(extensions, fileText.toString()));
		}
		// now add playlist as group of files
		chooserFilterArray.add(PlayList.PLAYLIST_FILE_FILTER);

		// now add all playable files at the last step (container extensions and playlist files)
		String [] containerExtensions = MultimediaContainerManager.getSupportedFileExtensions();
		String [] fullSupportedExtensions = new String[containerExtensions.length + PlayList.SUPPORTEDPLAYLISTS.length];
		System.arraycopy(PlayList.SUPPORTEDPLAYLISTS, 0, fullSupportedExtensions, 0, PlayList.SUPPORTEDPLAYLISTS.length);
		System.arraycopy(containerExtensions, 0, fullSupportedExtensions, PlayList.SUPPORTEDPLAYLISTS.length, containerExtensions.length);
		chooserFilterArray.add(new FileChooserFilter(fullSupportedExtensions, "All playable files"));
		// add default "all files" - WE DO NOT DO THAT ANYMORE ;)
//		chooserFilterArray.add(new FileChooserFilter("*", "All files"));
		
		fileFilterLoad = new FileFilter[chooserFilterArray.size()];
		chooserFilterArray.toArray(fileFilterLoad);

		fileFilterExport = new FileFilter[1];
		fileFilterExport[0] = new FileChooserFilter(javax.sound.sampled.AudioFileFormat.Type.WAVE.getExtension(), javax.sound.sampled.AudioFileFormat.Type.WAVE.toString());
	}
97125
@SuppressWarnings("resource")
    public static Scanner streamToScanner( InputStream stream, String delimiter ) {
        java.util.Scanner s = new java.util.Scanner(stream).useDelimiter(delimiter);
        return s;
    }
819336
private <F extends FileDescriptor> void scanPath(MavenProjectDirectoryDescriptor projectDescriptor, String path, Scope scope, Scanner scanner) {
        File file = new File(path);
        if (!file.exists()) {
            LOGGER.debug(file.getAbsolutePath() + " does not exist, skipping.");
        } else {
            F fileDescriptor = scanFile(projectDescriptor, file, path, scope, scanner);
            if (fileDescriptor != null) {
                projectDescriptor.getContains().add(fileDescriptor);
            }
        }
    }
727360
public static List<File> getAllFilesFromDir(final File dir)
	{
		final List<File> foundedFileList = new ArrayList<>();
		final File[] children = dir.getAbsoluteFile().listFiles();
		if (children == null || children.length < 1)
		{
			return foundedFileList;
		}
		for (final File child : children)
		{
			// if the entry is not a directory
			if (!child.isDirectory())
			{
				// then
				// entry is a file
				foundedFileList.add(child.getAbsoluteFile());
			}
		}
		return foundedFileList;
	}
34924
public static Iterator<File> get(String directoryIteratorType, File dir,
            String extensionFilter, boolean recursive) throws IOException {

        try {
            // add package name to e.g. "DefaultDirectoryIterator"
            if (directoryIteratorType.indexOf('.') == -1) {
                directoryIteratorType = DirectoryIterator.class.getPackage()
                        .getName() + "." + directoryIteratorType;
            }

            DirectoryIterator it = (DirectoryIterator) Class.forName(
                    directoryIteratorType).newInstance();
            it.setDirectory(dir);
            it.setRecursive(recursive);

            if (extensionFilter != null)
                it.setExtensionFilter(extensionFilter);
            return it.iterator();
        } catch (Throwable t) {
            throw new IOException(t);
        }
    }
453974
public static boolean containsFileRecursive(final File parent, final File search)
	{
		final File toSearch = search.getAbsoluteFile();
		boolean exists = false;
		final File[] children = parent.getAbsoluteFile().listFiles();
		if (children == null)
		{
			return false;
		}
		final List<File> fileList = Arrays.asList(children);
		for (final File currentFile : fileList)
		{
			if (currentFile.isDirectory())
			{
				exists = FileSearchExtensions.containsFileRecursive(currentFile, toSearch);
				if (exists)
				{
					return true;
				}
			}
			if (fileList.contains(toSearch))
			{
				return true;
			}
		}
		return exists;
	}
353477
public JournalBuilder setArchived(File to) {
        if (!to.exists()) {
            throw new IllegalArgumentException("<" + to + "> does not exist");
        }
        if (!to.isDirectory()) {
            throw new IllegalArgumentException("<" + to + "> is not a directory");
        }
        this.directoryArchive = to;
        return this;
    }