Search in sources :

Example 91 with FileFilter

use of java.io.FileFilter in project jabref by JabRef.

the class EntryFromFileCreatorManager method getFileFilterList.

/**
     * Returns a list of all {@link FileFilter} instances (i.e.
     * {@link EntryFromFileCreator}, plus the file filter that comes with the
     * {@link #getFileFilter()} method.
     *
     * @return A List of all known possible file filters.
     */
public List<FileFilter> getFileFilterList() {
    List<FileFilter> filters = new ArrayList<>();
    filters.add(getFileFilter());
    for (FileFilter creator : entryCreators) {
        filters.add(creator);
    }
    return filters;
}
Also used : ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter)

Example 92 with FileFilter

use of java.io.FileFilter in project CorfuDB by CorfuDB.

the class StreamLogFiles method trimPrefix.

private void trimPrefix() {
    // Trim all segments up till the segment that contains the starting address
    // (i.e. trim only complete segments)
    long endSegment = (startingAddress / RECORDS_PER_LOG_FILE) - 1;
    if (endSegment <= 0) {
        log.debug("Only one segment detected, ignoring trim");
        return;
    }
    File dir = new File(logDir);
    FileFilter fileFilter = new FileFilter() {

        public boolean accept(File file) {
            String segmentStr = file.getName().split("\\.")[0];
            return Long.parseLong(segmentStr) <= endSegment;
        }
    };
    File[] files = dir.listFiles(fileFilter);
    for (File file : files) {
        if (!file.delete()) {
            log.error("Couldn't delete/trim file {}", file.getName());
        }
    }
    log.info("Prefix trim completed, delete segments 0 to {}", endSegment);
}
Also used : ByteString(com.google.protobuf.ByteString) FileFilter(java.io.FileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File)

Example 93 with FileFilter

use of java.io.FileFilter in project sling by apache.

the class AbstractBundleListMojo method copyDirectory.

/**
     * Helper method to copy a whole directory
     */
protected void copyDirectory(final File source, final File target, final String[] includes, final String[] excludes) throws IOException {
    final String prefix = source.getAbsolutePath() + File.separatorChar;
    final int prefixLength = prefix.length();
    org.apache.commons.io.FileUtils.copyDirectory(source, target, new FileFilter() {

        public boolean accept(final File file) {
            final String path = file.getAbsolutePath().substring(prefixLength).replace(File.separatorChar, '/');
            if (includes != null) {
                boolean matched = false;
                for (int i = 0; i < includes.length && !matched; i++) {
                    if (SelectorUtils.matchPath(includes[i], path)) {
                        matched = true;
                    }
                }
                if (!matched) {
                    return false;
                }
            }
            if (excludes != null) {
                for (final String pattern : excludes) {
                    if (SelectorUtils.matchPath(pattern, path)) {
                        return false;
                    }
                }
            }
            return true;
        }
    });
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File)

Example 94 with FileFilter

use of java.io.FileFilter in project sling by apache.

the class Loader method getLauncherJarFiles.

/**
     * Returns all files in the <code>launchpadHome</code> directory which may
     * be considered as launcher JAR files, sorted based on their bundle version
     * information, most recent last. These files all start with the
     * {@link SharedConstants#LAUNCHER_JAR_REL_PATH}. This list may be empty if
     * the launcher JAR file has not been installed yet.
     *
     * @return The list of candidate launcher JAR files, which may be empty.
     *         <code>null</code> is returned if an IO error occurs trying to
     *         list the files.
     */
private File[] getLauncherJarFiles() {
    // Get list of files with names starting with our prefix
    final File[] rawList = launchpadHome.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isFile() && pathname.getName().startsWith(SharedConstants.LAUNCHER_JAR_REL_PATH);
        }
    });
    // Keep only those which have valid Bundle headers, and
    // sort them according to the bundle version numbers
    final List<FileBundleVersionInfo> list = new ArrayList<FileBundleVersionInfo>();
    for (File f : rawList) {
        FileBundleVersionInfo fvi = null;
        try {
            fvi = new FileBundleVersionInfo(f);
        } catch (IOException ioe) {
            // Cannot read bundle info from jar file - should never happen??
            throw new IllegalStateException("Cannot read bundle information from loader file " + f.getAbsolutePath());
        }
        if (fvi.isBundle()) {
            list.add(fvi);
        }
    }
    Collections.sort(list);
    final File[] result = new File[list.size()];
    int i = 0;
    for (FileBundleVersionInfo fvi : list) {
        result[i++] = fvi.getSource();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileFilter(java.io.FileFilter) JarFile(java.util.jar.JarFile) File(java.io.File) FileBundleVersionInfo(org.apache.sling.commons.osgi.bundleversion.FileBundleVersionInfo)

Example 95 with FileFilter

use of java.io.FileFilter in project intellij-plugins by JetBrains.

the class FlashBuilderSdkFinder method findFBInstallationPath.

@Nullable
public static String findFBInstallationPath() {
    final List<File> fbDirs = new ArrayList<>();
    final FileFilter filter = dir -> {
        final String name = dir.getName();
        return dir.isDirectory() && (name.contains("Flash") || name.contains("Flex")) && name.contains("Builder") && new File(dir, SDKS_FOLDER).isDirectory();
    };
    final String programsPath = SystemInfo.isMac ? "/Applications" : SystemInfo.isWindows ? System.getenv("ProgramFiles") : null;
    final File programsDir = programsPath == null ? null : new File(programsPath);
    if (programsDir != null && programsDir.isDirectory()) {
        Collections.addAll(fbDirs, programsDir.listFiles(filter));
        final File adobeDir = new File(programsDir, "Adobe");
        if (adobeDir.isDirectory()) {
            Collections.addAll(fbDirs, adobeDir.listFiles(filter));
        }
    }
    if (SystemInfo.isWindows) {
        final String programs64Path = System.getenv("ProgramW6432");
        final File programs64Dir = programs64Path == null ? null : new File(programs64Path);
        if (programs64Dir != null && programs64Dir.isDirectory()) {
            Collections.addAll(fbDirs, programs64Dir.listFiles(filter));
            final File adobeDir = new File(programs64Dir, "Adobe");
            if (adobeDir.isDirectory()) {
                Collections.addAll(fbDirs, adobeDir.listFiles(filter));
            }
        }
    }
    if (fbDirs.size() == 0)
        return null;
    if (fbDirs.size() == 1)
        return fbDirs.get(0).getPath();
    // check the most recent
    Pair<String, String> pathAndVersion = null;
    for (File fbDir : fbDirs) {
        final String version = guessFBVersion(fbDir.getName());
        if (pathAndVersion == null || StringUtil.compareVersionNumbers(version, pathAndVersion.second) > 0) {
            pathAndVersion = Pair.create(fbDir.getPath(), version);
        }
    }
    assert pathAndVersion != null;
    return pathAndVersion.first;
}
Also used : FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) SelectFlexSdkDialog(com.intellij.lang.javascript.flex.projectStructure.ui.SelectFlexSdkDialog) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) JDOMException(org.jdom.JDOMException) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JDOMUtil(com.intellij.openapi.util.JDOMUtil) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) StringUtil(com.intellij.openapi.util.text.StringUtil) Attribute(org.jdom.Attribute) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) FileFilter(java.io.FileFilter) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) FileFilter(java.io.FileFilter) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileFilter (java.io.FileFilter)281 File (java.io.File)267 ArrayList (java.util.ArrayList)59 IOException (java.io.IOException)53 JarFile (java.util.jar.JarFile)22 URL (java.net.URL)17 Test (org.junit.Test)16 HashMap (java.util.HashMap)15 FileNotFoundException (java.io.FileNotFoundException)11 FilenameFilter (java.io.FilenameFilter)11 HashSet (java.util.HashSet)11 FileInputStream (java.io.FileInputStream)10 Pattern (java.util.regex.Pattern)10 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)10 MalformedURLException (java.net.MalformedURLException)9 URI (java.net.URI)9 Map (java.util.Map)7 Path (org.apache.hadoop.fs.Path)7 NotNull (org.jetbrains.annotations.NotNull)7 Treebank (edu.stanford.nlp.trees.Treebank)6