Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

In this page you can find the example usage for java.io FilenameFilter FilenameFilter.

Prototype

FilenameFilter

Source Link

Usage

From source file:com.coinblesk.client.backup.BackupRestoreDialogFragment.java

private void initBackupFilesList() {
    File backupDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    File[] files = backupDir.listFiles(new FilenameFilter() {
        @Override// w w  w  .j  ava 2 s  .co  m
        public boolean accept(File dir, String filename) {
            return filename.startsWith(Constants.BACKUP_FILE_PREFIX);
        }
    });

    List<File> backupFiles = new ArrayList<>();
    if (files != null) {
        for (File f : files) {
            backupFiles.add(f);
        }
    }
    Collections.sort(backupFiles);
    ArrayAdapter<File> fileAdapter = new ArrayAdapter<>(getContext(), R.layout.simple_multiline_list_item,
            R.id.text1, backupFiles);
    backupFilesList.setAdapter(fileAdapter);
}

From source file:com.sikulix.core.SX.java

static void sxinit(String[] args) {
    if (null == sxInstance) {
        sxInstance = "SX INIT DONE";

        //<editor-fold desc="*** shutdown hook">
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override/*from  w w  w .  j  a va 2s  . co  m*/
            public void run() {
                if (shouldLock && isSet(isRunningFile)) {
                    try {
                        isRunningFile.close();
                    } catch (IOException ex) {
                    }
                }
                for (File f : getFile(getSYSTEMP()).listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        File aFile = new File(dir, name);
                        boolean isObsolete = false;
                        long lastTime = aFile.lastModified();
                        if (lastTime == 0) {
                            return false;
                        }
                        if (lastTime < ((new Date().getTime()) - 7 * 24 * 60 * 60 * 1000)) {
                            isObsolete = true;
                        }
                        if (name.contains("BridJExtractedLibraries") && isObsolete) {
                            return true;
                        }
                        if (name.toLowerCase().contains("sikuli")) {
                            if (name.contains("Sikulix_")) {
                                if (isObsolete || aFile.equals(getFile(getSXTEMP()))) {
                                    return true;
                                }
                            } else {
                                return true;
                            }
                        }
                        return false;
                    }
                })) {
                    trace("cleanTemp: " + f.getName());
                    Content.deleteFileOrFolder("#" + f.getAbsolutePath());
                }
            }
        });
        //</editor-fold>

        // TODO Content class must be initialized for use in shutdown
        Content.start();

        //<editor-fold desc="*** sx lock (not active)">
        if (shouldLock) {
            File fLock = new File(getSYSTEMP(), "SikuliX2-i-s-r-u-n-n-i-n-g");
            String shouldTerminate = "";
            try {
                fLock.createNewFile();
                isRunningFile = new FileOutputStream(fLock);
                if (isNull(isRunningFile.getChannel().tryLock())) {
                    shouldTerminate = "SikuliX2 already running";
                    isRunningFile = null;
                }
            } catch (Exception ex) {
                shouldTerminate = "cannot access SX2 lock: " + ex.toString();
                isRunningFile = null;
            }
            if (isSet(shouldTerminate)) {
                terminate(1, shouldTerminate);
            }
        }
        //</editor-fold>

        // *** command line args
        if (!isNull(args)) {
            checkArgs(args);
        }

        trace("!sxinit: entry");

        // *** get SX options
        loadOptions();

        // *** get the version info
        getSXVERSION();

        // *** check how we are running
        sxRunningAs();

        // *** get monitor setup
        globalGetMonitors();

        //TODO i18n SXGlobal_sxinit_complete=complete %.3f
        trace("!sxinit: exit %.3f", (new Date().getTime() - startTime) / 1000.0f);
    }
}

From source file:eu.openanalytics.rsb.RestJobsITCase.java

@After
public void cleanupResults() throws IOException {
    final Configuration configuration = getConfiguration();
    if (configuration == null) {
        return;//from   w  w  w . ja  va2s  .com
    }

    final File[] testResultFiles = configuration.getResultsDirectory().listFiles(new FilenameFilter() {
        public boolean accept(final File dir, final String name) {
            return StringUtils.startsWith(name, TEST_APPLICATION_NAME_PREFIX);
        }
    });

    if (testResultFiles == null) {
        return;
    }

    for (final File testResultFile : testResultFiles) {
        FileUtils.deleteQuietly(testResultFile);
    }
}

From source file:com.googlecode.fascinator.storage.filesystem.FileSystemDigitalObject.java

private void readFromDisk(Map<String, Payload> manifest, File dir, int depth) {
    File[] files = dir.listFiles(new FilenameFilter() {
        @Override//from  ww w .j  av a2s. com
        public boolean accept(File dir, String name) {
            if (name.endsWith(METADATA_SUFFIX)) {
                return false;
            }
            if (name.endsWith(MANIFEST_LOCK_FILE)) {
                return false;
            }
            return true;
        }
    });
    if (files != null) {
        for (File file : files) {
            if (file.isFile()) {
                FileSystemPayload payload = null;
                File payloadFile = file;
                if (depth > 0) {
                    File parentFile = file.getParentFile();
                    String relPath = "";
                    for (int i = 0; i < depth; i++) {
                        relPath = parentFile.getName() + File.separator + relPath;
                        parentFile = parentFile.getParentFile();
                    }
                    payloadFile = new File(relPath, file.getName());
                    payload = new FileSystemPayload(relPath + file.getName(),
                            new File(homeDir, payloadFile.getPath()));
                } else {
                    // log.debug("File found on disk : " +
                    // payloadFile.getName());
                    payload = new FileSystemPayload(payloadFile.getName(), payloadFile);
                }
                payload.readExistingMetadata();
                if (payload.getType().equals(PayloadType.Source)) {
                    setSourceId(payload.getId());
                }
                manifest.put(payload.getId(), payload);
            } else if (file.isDirectory()) {
                readFromDisk(manifest, file, depth + 1);
            }
        }
    }
    // log.debug("New Manifest : " + manifest);
}

From source file:edu.kit.dama.util.ZipUtils.java

/**
 * Compress all files of one directory with given extensions to a single zip
 * file./*from  www.  jav  a 2  s .  c  o m*/
 *
 * @param pZipFile resulting zip File. Existing file will be overwritten!
 * @param pDirectory directory to explore.
 * @param pExtension allowed file name extensions of files to compress
 * @return success or not.
 */
public static boolean zipDirectory(final File pZipFile, final File pDirectory, final String... pExtension) {
    boolean success = false;
    File[] files = pDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            boolean accept = false;
            String lowerCase = name.toLowerCase();
            if (pExtension != null) {
                for (String extension : pExtension) {
                    if (lowerCase.endsWith(extension.toLowerCase())) {
                        accept = true;
                        break;
                    }
                }
            } else {
                accept = true;
            }
            return accept;
        }
    });
    if (LOGGER.isDebugEnabled()) {
        String fileSeparator = ", ";
        LOGGER.debug("Zip files to " + pZipFile.getName());
        StringBuilder sb = new StringBuilder("Selected files: ");
        for (File file : files) {
            sb.append(file.getName()).append(fileSeparator);
        }
        int lastIndex = sb.lastIndexOf(fileSeparator);
        sb.delete(lastIndex, lastIndex + fileSeparator.length());
        LOGGER.debug(sb.toString());
    }
    try {
        zip(files, pDirectory.getPath(), pZipFile);
        success = true;
    } catch (IOException ex) {
        LOGGER.error("Error while zipping files!", ex);
    }
    return success;
}

From source file:dk.statsbiblioteket.alto.AnagramHashing.java

/**
 * Get all ALTO XML files from the folder and sub folders.
 * @param altos  located ALTO XML files will be added to this.
 * @param folder where to start looking for ALTO XML files.
 *///from   ww  w  .  ja  v  a  2s .com
public void getALTOs(List<File> altos, File folder) {
    altos.addAll(Arrays.asList(folder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return (name.endsWith(".alto.xml"));
        }
    })));
    for (File sub : folder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    })) {
        getALTOs(altos, sub);
    }
}

From source file:com.gitblit.tests.HtpasswdAuthenticationTest.java

private void copyInFiles() throws IOException {
    File dir = new File(RESOURCE_DIR);
    FilenameFilter filter = new FilenameFilter() {
        @Override/*from w  ww  .  jav  a  2s  . co  m*/
        public boolean accept(File dir, String file) {
            return file.endsWith(".in");
        }
    };
    for (File inf : dir.listFiles(filter)) {
        File dest = new File(inf.getParent(), inf.getName().substring(0, inf.getName().length() - 3));
        FileUtils.copyFile(inf, dest);
    }
}

From source file:de.chdev.artools.loga.lang.KeywordLoader.java

private List<Configuration> getAllConfigurations() {
    List<Configuration> localConfigurationList = new ArrayList<Configuration>();
    try {/*from  w w w  . j a  v a 2s.c  om*/
        // File path = new File("./config");

        // File[] listFiles = path.listFiles();

        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                if (name.startsWith("keywords")) {
                    return true;
                } else {
                    return false;
                }
            }

        };

        /* TESTCODE */
        // Bundle location = Activator.getDefault().getBundle();
        // Enumeration entryPaths =
        // Activator.getDefault().getBundle().getEntryPaths("/");
        URL configEntry = Activator.getDefault().getBundle().getEntry("config");
        URL configPath = FileLocator.resolve(configEntry);
        File path = new File(configPath.getFile());
        // String[] list2 = resFile.list();
        // File file = new ConfigurationScope().getLocation().toFile();
        // String[] list = file.list();
        // IProject project = root.getProject();
        // IFolder files = project.getFolder("");
        // IResource[] members = files.members();
        /* TESTCODE END */

        String[] fileNames = path.list(filter);
        supportedLanguages.clear();

        for (String fileName : fileNames) {
            File fileObj = new File(path, fileName);
            CompositeConfiguration configuration = new CompositeConfiguration();

            PropertiesConfiguration keywords = new PropertiesConfiguration(fileObj);
            configuration.addConfiguration(keywords);
            configuration.addProperty("filename", fileName);
            localConfigurationList.add(configuration);
            supportedLanguages.add(configuration.getString("language.name"));
            nameConfigMap.put(configuration.getString("language.name"), configuration);
        }

        // for (String fileName : fileNames) {
        // CompositeConfiguration configuration = new
        // CompositeConfiguration();
        //
        // PropertiesConfiguration keywords = new PropertiesConfiguration(
        // "config/" + fileName);
        // configuration.addConfiguration(keywords);
        // configuration.addProperty("filename", fileName);
        // localConfigurationList.add(configuration);
        // }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return localConfigurationList;
}

From source file:com.nullwire.ExceptionHandler.java

/**
 * Search for stack trace files.//from  w  w  w  .  j a va  2  s .c o  m
 * @return
 */
private static String[] searchForStackTraces() {
    if (stackTraceFileList != null) {
        return stackTraceFileList;
    }
    File dir = new File(G.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".stacktrace" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");
        }
    };
    return (stackTraceFileList = dir.list(filter));
}