Search in sources :

Example 81 with FilenameFilter

use of java.io.FilenameFilter in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class UserHistoryDictionaryTestsHelper method removeAllTestDictFiles.

/**
     * Remove all the test dictionary files created for the given locale.
     */
public static void removeAllTestDictFiles(final String filter, final Context context) {
    final FilenameFilter filenameFilter = new FilenameFilter() {

        @Override
        public boolean accept(final File dir, final String filename) {
            return filename.startsWith(UserHistoryDictionary.NAME + "." + filter);
        }
    };
    FileUtils.deleteFilteredFiles(context.getFilesDir(), filenameFilter);
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 82 with FilenameFilter

use of java.io.FilenameFilter in project atmosphere by Atmosphere.

the class AtmosphereFramework method autoConfigureService.

protected void autoConfigureService(ServletContext sc) throws IOException {
    String path = handlersPath != DEFAULT_HANDLER_PATH ? handlersPath : realPath(sc, handlersPath);
    try {
        annotationProcessor = newClassInstance(AnnotationProcessor.class, (Class<AnnotationProcessor>) IOUtils.loadClass(getClass(), annotationProcessorClassName));
        logger.info("Atmosphere is using {} for processing annotation", annotationProcessorClassName);
        annotationProcessor.configure(config);
        if (!packages.isEmpty()) {
            for (String s : packages) {
                annotationProcessor.scan(s);
            }
        }
        // Second try.
        if (!annotationFound) {
            if (path != null) {
                annotationProcessor.scan(new File(path));
            }
            // Always scan library
            String pathLibs = libPath != DEFAULT_LIB_PATH ? libPath : realPath(sc, DEFAULT_LIB_PATH);
            if (pathLibs != null) {
                File libFolder = new File(pathLibs);
                File[] jars = libFolder.listFiles(new FilenameFilter() {

                    @Override
                    public boolean accept(File arg0, String arg1) {
                        return arg1.endsWith(".jar");
                    }
                });
                if (jars != null) {
                    for (File file : jars) {
                        annotationProcessor.scan(file);
                    }
                }
            }
        }
        if (!annotationFound && allowAllClassesScan) {
            logger.debug("Scanning all classes on the classpath");
            annotationProcessor.scanAll();
        }
    } catch (Throwable e) {
        logger.error("", e);
        return;
    } finally {
        if (annotationProcessor != null) {
            annotationProcessor.destroy();
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 83 with FilenameFilter

use of java.io.FilenameFilter in project atmosphere by Atmosphere.

the class DefaultAnnotationProcessor method scanForAnnotation.

private void scanForAnnotation(AtmosphereFramework f) {
    List<String> packages = f.customAnnotationPackages();
    AnnotationDetector detector = new AnnotationDetector(atmosphereReporter);
    try {
        if (!packages.isEmpty()) {
            for (String p : packages) {
                logger.trace("Package {} scanned for @AtmosphereAnnotation", p);
                detector.detect(p);
            }
        }
        // Now look for application defined annotation
        String path = IOUtils.realPath(f.getServletContext(), f.getHandlersPath());
        if (path != null) {
            detector.detect(new File(path));
        }
        String pathLibs = IOUtils.realPath(f.getServletContext(), f.getLibPath());
        if (pathLibs != null) {
            File libFolder = new File(pathLibs);
            File[] jars = libFolder.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File arg0, String arg1) {
                    return arg1.endsWith(".jar");
                }
            });
            if (jars != null) {
                for (File file : jars) {
                    detector.detect(file);
                }
            }
        }
        // https://github.com/Atmosphere/atmosphere/issues/1292
        if (!coreAnnotationsFound.get()) {
            fallbackToManualAnnotatedClasses(getClass(), f, handler);
        }
    } catch (IOException e) {
        logger.warn("Unable to scan annotation", e);
    } finally {
        detector.destroy();
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) AnnotationDetector(org.atmosphere.util.annotation.AnnotationDetector) IOException(java.io.IOException) File(java.io.File)

Example 84 with FilenameFilter

use of java.io.FilenameFilter in project AndroidChromium by JackyAndroid.

the class CrashFileManager method getMatchingFiles.

@VisibleForTesting
File[] getMatchingFiles(final Pattern pattern) {
    // Get dump dir and get all files with specified suffix. The path
    // constructed here must match chrome_paths.cc (see case
    // chrome::DIR_CRASH_DUMPS).
    File crashDir = getCrashDirectoryIfExists();
    if (crashDir == null) {
        return new File[] {};
    }
    File[] minidumps = crashDir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String filename) {
            Matcher match = pattern.matcher(filename);
            int tries = readAttemptNumber(filename);
            return match.find() && tries < MinidumpUploadService.MAX_TRIES_ALLOWED;
        }
    });
    return minidumps;
}
Also used : FilenameFilter(java.io.FilenameFilter) Matcher(java.util.regex.Matcher) File(java.io.File) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 85 with FilenameFilter

use of java.io.FilenameFilter in project zaproxy by zaproxy.

the class LocaleUtils method readAvailableLocales.

private static List<String> readAvailableLocales() {
    File dir = new File(Constant.getZapInstall(), Constant.LANG_DIR);
    FilenameFilter filter = new MessagesPropertiesFilenameFilter();
    String[] files = dir.list(filter);
    if (files == null || files.length == 0) {
        logger.error("Failed to find any locale files in directory " + dir.getAbsolutePath());
        return new ArrayList<>(0);
    }
    List<String> locales = new ArrayList<>(files.length);
    final int baseFilenameLength = MESSAGES_BASE_FILENAME.length();
    for (String file : Arrays.asList(files)) {
        if (file.startsWith(MESSAGES_BASE_FILENAME)) {
            locales.add(file.substring(baseFilenameLength, file.indexOf(".")));
        }
    }
    return locales;
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

FilenameFilter (java.io.FilenameFilter)402 File (java.io.File)398 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)72 Test (org.junit.Test)60 URL (java.net.URL)22 List (java.util.List)22 RandomAccessFile (java.io.RandomAccessFile)19 HashSet (java.util.HashSet)17 FileOutputStream (java.io.FileOutputStream)14 JarFile (java.util.jar.JarFile)14 FileNotFoundException (java.io.FileNotFoundException)13 MalformedURLException (java.net.MalformedURLException)13 HashMap (java.util.HashMap)13 FileFilter (java.io.FileFilter)11 FileWriter (java.io.FileWriter)11 ZipFile (java.util.zip.ZipFile)11 TestClient (org.syncany.tests.util.TestClient)11 FileReader (java.io.FileReader)10 Pattern (java.util.regex.Pattern)10