Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:org.opendatakit.utilities.ODKFileUtils.java

/**
 * Used in AndroidShortcuts//from w w w.j a  va2  s.  c o  m
 *
 * @return a list of all the folders in /sdcard/opendatakit
 */
@SuppressWarnings("unused")
public static File[] getAppFolders() {
    return new File(getOdkFolder()).listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });
}

From source file:adalid.commons.util.FilUtils.java

public static FileFilter nameEndsWithFilter(final String suffix) {
    return new FileFilter() {

        @Override//ww  w .ja  v  a2 s .c o m
        public boolean accept(File file) {
            return isVisibleFile(file) && StringUtils.endsWithIgnoreCase(file.getName(), suffix);
        }

    };
}

From source file:org.apache.cassandra.db.Directories.java

/**
 * Create Directories of given ColumnFamily.
 * SSTable directories are created under data_directories defined in cassandra.yaml if not exist at this time.
 *
 * @param metadata metadata of ColumnFamily
 *//* w w w  .  j a va  2 s. co m*/
public Directories(final CFMetaData metadata) {
    this.metadata = metadata;

    String cfId = ByteBufferUtil.bytesToHex(ByteBufferUtil.bytes(metadata.cfId));
    int idx = metadata.cfName.indexOf(SECONDARY_INDEX_NAME_SEPARATOR);
    String cfName = idx >= 0 ? metadata.cfName.substring(0, idx) : metadata.cfName;
    String indexNameWithDot = idx >= 0 ? metadata.cfName.substring(idx) : null;

    this.dataPaths = new File[dataDirectories.length];
    // If upgraded from version less than 2.1, use existing directories
    String oldSSTableRelativePath = join(metadata.ksName, cfName);
    for (int i = 0; i < dataDirectories.length; ++i) {
        // check if old SSTable directory exists
        dataPaths[i] = new File(dataDirectories[i].location, oldSSTableRelativePath);
    }
    boolean olderDirectoryExists = Iterables.any(Arrays.asList(dataPaths), new Predicate<File>() {
        public boolean apply(File file) {
            return file.exists();
        }
    });
    if (!olderDirectoryExists) {
        // use 2.1+ style
        String newSSTableRelativePath = join(metadata.ksName, cfName + '-' + cfId);
        for (int i = 0; i < dataDirectories.length; ++i)
            dataPaths[i] = new File(dataDirectories[i].location, newSSTableRelativePath);
    }
    // if index, then move to its own directory
    if (indexNameWithDot != null) {
        for (int i = 0; i < dataDirectories.length; ++i)
            dataPaths[i] = new File(dataPaths[i], indexNameWithDot);
    }

    for (File dir : dataPaths) {
        try {
            FileUtils.createDirectory(dir);
        } catch (FSError e) {
            // don't just let the default exception handler do this, we need the create loop to continue
            logger.error("Failed to create {} directory", dir);
            FileUtils.handleFSError(e);
        }
    }

    // if index, move existing older versioned SSTable files to new directory
    if (indexNameWithDot != null) {
        for (File dataPath : dataPaths) {
            File[] indexFiles = dataPath.getParentFile().listFiles(new FileFilter() {
                @Override
                public boolean accept(File file) {
                    if (file.isDirectory())
                        return false;

                    Pair<Descriptor, Component> pair = SSTable.tryComponentFromFilename(file.getParentFile(),
                            file.getName());
                    return pair != null && pair.left.ksname.equals(metadata.ksName)
                            && pair.left.cfname.equals(metadata.cfName);

                }
            });
            for (File indexFile : indexFiles) {
                File destFile = new File(dataPath, indexFile.getName());
                logger.trace("Moving index file {} to {}", indexFile, destFile);
                FileUtils.renameWithConfirm(indexFile, destFile);
            }
        }
    }
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidBatchScaleImporter.java

private void addImageFiles(File file) {
    if (file == null) {
        return;/*from w w w  .  j  ava  2 s  .co  m*/
    }

    if (!file.isDirectory()) {
        ImageInformation item = parseImageInformation(file);
        if (item != null) {
            tableModel.addItem(item);
        }
    } else {
        File[] files = file.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return true;
                }
                String mimetype = new MimetypesFileTypeMap().getContentType(file);
                String type = mimetype.split("/")[0];
                return type.equals("image");
            }
        });

        for (File foundFile : files) {
            addImageFiles(foundFile);
        }
    }
}

From source file:com.demandware.vulnapp.util.Helpers.java

public static File[] lastFileModifiedByExt(File dir, String ext) {
    File[] files = dir.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.isFile() && Helpers.getFileExtension(file.getName()).equals(ext);
        }/* w w w  .j  a  v  a2s.c  om*/
    });

    Arrays.sort(files, new Comparator<File>() {
        public int compare(File f1, File f2) {
            return Long.valueOf(f2.lastModified()).compareTo(f1.lastModified());
        }
    });

    return files;
}

From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java

private static File getDigitvBroadcastFile(TranscodeRequest request, ServletConfig config) {
    final String filenameWithoutExtension = getDigitvProgramFilenameWithoutExtension(request);
    final FileFilter filter = new FileFilter() {
        @Override/*from  w  ww.ja v  a2s.com*/
        public boolean accept(File pathname) {
            return pathname.getName().startsWith(filenameWithoutExtension);
        }
    };
    File outputDir = getBaseOutputDir(request, config);
    log.trace("Looking for output in directory '" + outputDir + "'");
    return outputDir.listFiles(filter)[0];
}

From source file:ml.shifu.shifu.core.processor.ManageModelProcessor.java

/**
 * save model to back_models folder//from www.  j a v  a 2  s  . c  o  m
 *
 * @param modelName
 * @throws IOException
 */
private void saveModel(String modelName) throws IOException {

    if (modelName == null) {
        modelName = getCurrentModelName();
    } else {
        //tell shifu switch to modelName
        File file = new File("./.HEAD");
        BufferedWriter writer = null;
        try {
            FileUtils.deleteQuietly(file);
            writer = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(file), Constants.DEFAULT_CHARSET));
            writer.write(modelName);
        } catch (IOException e) {
            log.info("Fail to rewrite HEAD file");
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }

    log.info("The current model will be saved to {} folder", modelName);

    File configFolder = new File(Constants.BACKUPNAME + File.separator + modelName);

    try {
        if (configFolder.exists()) {
            log.info("The model {} folder exists, it will be replaced by current model", modelName);

            FileUtils.deleteDirectory(configFolder);

        }
    } catch (IOException e) {
        log.error("Fail to delete historical folder, please manually delete it : {}",
                configFolder.getAbsolutePath());
    }

    FileUtils.forceMkdir(configFolder);

    // copy configs
    File modelFile = new File("./ModelConfig.json");
    File columnFile = new File("./ColumnConfig.json");

    try {
        FileUtils.copyFileToDirectory(modelFile, configFolder);
        if (columnFile.exists()) {
            FileUtils.copyFileToDirectory(columnFile, configFolder);
        }
    } catch (IOException e) {
        log.error("Fail in copy config file");
    }

    // copy models
    File modelFolder = new File(Constants.BACKUPNAME + File.separator + modelName + File.separator + "models");

    FileUtils.forceMkdir(modelFolder);

    File currentModelFoler = new File("models");
    if (currentModelFoler.isDirectory()) {
        File[] files = currentModelFoler.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isFile() && file.getName().startsWith("model");
            }
        });

        if (files != null) {
            for (File model : files) {
                try {
                    FileUtils.copyFileToDirectory(model, modelFolder);
                } catch (IOException e) {
                    log.error("Fail in copy model file, source: {}", model.getAbsolutePath());
                }
            }
        } else {
            throw new IOException(
                    String.format("Failed to list files in %s", currentModelFoler.getAbsolutePath()));
        }

        log.info("Save model: {} successfully", modelName);
    } else {
        log.error("Save model: {} failed", modelName);
        log.error("{} does not exist or not a directory!", currentModelFoler.getAbsolutePath());
    }
}

From source file:adalid.commons.util.FilUtils.java

public static FileFilter nameStartsWithFilter(final String prefix) {
    return new FileFilter() {

        @Override/*from w ww.j  a  v  a  2  s . c o  m*/
        public boolean accept(File file) {
            return isVisibleFile(file) && StringUtils.startsWithIgnoreCase(file.getName(), prefix);
        }

    };
}

From source file:och.util.FileUtil.java

public static File[] listFilesWithNameStart(File root, final String nameStart) {
    return root.listFiles(new FileFilter() {

        @Override/*from ww w  . ja v a  2s.  c  om*/
        public boolean accept(File file) {
            return file.getName().startsWith(nameStart);
        }
    });
}

From source file:ch.admin.suis.msghandler.signer.SignerTest.java

private List<File> getAllFilesFromDir(File directory) {
    if (directory == null) {
        return new ArrayList<File>();
    }/*from   ww  w . ja va2s  . co  m*/

    File[] files = ch.admin.suis.msghandler.util.FileUtils.listFiles(directory, new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isFile() && ch.admin.suis.msghandler.util.FileUtils.canRead(pathname)
                    && !pathname.isHidden();
        }
    });

    List<File> retVal = new ArrayList();
    Collections.addAll(retVal, files);
    return retVal;
}