Search in sources :

Example 41 with FileFilter

use of java.io.FileFilter in project Anki-Android by Ramblurr.

the class Utils method getImportableDecks.

/** Returns a list of apkg-files. */
public static List<File> getImportableDecks() {
    String deckPath = AnkiDroidApp.getCurrentAnkiDroidDirectory();
    File dir = new File(deckPath);
    int deckCount = 0;
    File[] deckList = null;
    if (dir.exists() && dir.isDirectory()) {
        deckList = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if (pathname.isFile() && pathname.getName().endsWith(".apkg")) {
                    return true;
                }
                return false;
            }
        });
        deckCount = deckList.length;
    }
    List<File> decks = new ArrayList<File>();
    for (int i = 0; i < deckCount; i++) {
        decks.add(deckList[i]);
    }
    return decks;
}
Also used : ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 42 with FileFilter

use of java.io.FileFilter in project StickerCamera by Skykai521.

the class FileUtils method findPicsInDir.

//获取path路径下的图片
public ArrayList<PhotoItem> findPicsInDir(String path) {
    ArrayList<PhotoItem> photos = new ArrayList<PhotoItem>();
    File dir = new File(path);
    if (dir.exists() && dir.isDirectory()) {
        for (File file : dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                String filePath = pathname.getAbsolutePath();
                return (filePath.endsWith(".png") || filePath.endsWith(".jpg") || filePath.endsWith(".jepg"));
            }
        })) {
            photos.add(new PhotoItem(file.getAbsolutePath(), file.lastModified()));
        }
    }
    Collections.sort(photos);
    return photos;
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File)

Example 43 with FileFilter

use of java.io.FileFilter in project android_frameworks_base by ParanoidAndroid.

the class SQLiteDatabase method deleteDatabase.

/**
     * Deletes a database including its journal file and other auxiliary files
     * that may have been created by the database engine.
     *
     * @param file The database file path.
     * @return True if the database was successfully deleted.
     */
public static boolean deleteDatabase(File file) {
    if (file == null) {
        throw new IllegalArgumentException("file must not be null");
    }
    boolean deleted = false;
    deleted |= file.delete();
    deleted |= new File(file.getPath() + "-journal").delete();
    deleted |= new File(file.getPath() + "-shm").delete();
    deleted |= new File(file.getPath() + "-wal").delete();
    File dir = file.getParentFile();
    if (dir != null) {
        final String prefix = file.getName() + "-mj";
        final FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File candidate) {
                return candidate.getName().startsWith(prefix);
            }
        };
        for (File masterJournal : dir.listFiles(filter)) {
            deleted |= masterJournal.delete();
        }
    }
    return deleted;
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File)

Example 44 with FileFilter

use of java.io.FileFilter in project jphp by jphp-compiler.

the class DocGenerator method main.

public static void main(String[] args) throws IOException {
    File root = new File(".").getCanonicalFile();
    DocGenerator generator = new DocGenerator();
    for (File file : root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    })) {
        File sdkFile1 = new File(file, "resources/JPHP-INF/sdk/");
        File sdkFile2 = new File(file, "src/main/resources/JPHP-INF/sdk/");
        if (sdkFile1.isDirectory()) {
            generator.addDirectory(sdkFile1, true);
        } else if (sdkFile2.isDirectory()) {
            generator.addDirectory(sdkFile2, true);
        }
    }
    for (Map.Entry<String, String> entry : languages.entrySet()) {
        generator.generate(new File("./docs/api_" + entry.getKey()), entry.getKey());
    }
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File) HashedMap(php.runtime.common.collections.map.HashedMap) Map(java.util.Map)

Example 45 with FileFilter

use of java.io.FileFilter in project hackpad by dropbox.

the class MozillaSuiteTest method main.

/**
     * The main class will run all the test files that are *not* covered in
     * the *.tests files, and print out a list of all the tests that pass.
     */
public static void main(String[] args) throws IOException {
    PrintStream out = new PrintStream("fix-tests-files.sh");
    try {
        for (int i = 0; i < OPT_LEVELS.length; i++) {
            int optLevel = OPT_LEVELS[i];
            File testDir = getTestDir();
            File[] allTests = TestUtils.recursiveListFiles(testDir, new FileFilter() {

                public boolean accept(File pathname) {
                    return ShellTest.DIRECTORY_FILTER.accept(pathname) || ShellTest.TEST_FILTER.accept(pathname);
                }
            });
            HashSet<File> diff = new HashSet<File>(Arrays.asList(allTests));
            File[] testFiles = getTestFiles(optLevel);
            diff.removeAll(Arrays.asList(testFiles));
            ArrayList<String> skippedPassed = new ArrayList<String>();
            int absolutePathLength = testDir.getAbsolutePath().length() + 1;
            for (File testFile : diff) {
                try {
                    (new MozillaSuiteTest(testFile, optLevel)).runMozillaTest();
                    // strip off testDir
                    String canonicalized = testFile.getAbsolutePath().substring(absolutePathLength);
                    canonicalized = canonicalized.replace('\\', '/');
                    skippedPassed.add(canonicalized);
                } catch (Throwable t) {
                // failed, so skip
                }
            }
            // appropriate *.tests file.
            if (skippedPassed.size() > 0) {
                out.println("cat >> " + getTestFilename(optLevel) + " <<EOF");
                String[] sorted = skippedPassed.toArray(new String[0]);
                Arrays.sort(sorted);
                for (int j = 0; j < sorted.length; j++) {
                    out.println(sorted[j]);
                }
                out.println("EOF");
            }
        }
        System.out.println("Done.");
    } finally {
        out.close();
    }
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

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