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:io.fabric8.maven.plugin.HelmMojo.java

private void copyTextFile(File outputDir, final String srcFile) throws MojoExecutionException {
    try {//from w w  w  .  j av a 2  s . c o  m
        FilenameFilter filter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                String lower = name.toLowerCase(Locale.ENGLISH);
                return lower.equals(srcFile.toLowerCase()) || lower.startsWith(srcFile.toLowerCase() + ".");
            }
        };
        copyFirstFile(project.getBasedir(), filter, new File(outputDir, srcFile));
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to save " + srcFile + ": " + e, e);
    }
}

From source file:com.laxser.blitz.web.instruction.ViewInstruction.java

/**
 * ???????/*from  w  w w . ja va2 s . c o  m*/
 * 
 * @param tempHome
 * @param subDirPath
 * @return
 */
private File searchDirectory(File tempHome, String subDirPath) {
    // 
    String[] subDirs = StringUtils.split(subDirPath, "/");
    for (final String subDir : subDirs) {
        File file = new File(tempHome, subDir);
        if (!file.exists()) {
            String[] candidates = tempHome.list(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    if (name.equalsIgnoreCase(subDir)) {
                        return true;
                    }
                    return false;
                }

            });
            if (candidates.length == 0) {
                tempHome = null;
                break;
            } else {
                tempHome = new File(tempHome, candidates[0]);
            }
        } else {
            tempHome = file;
        }
    }
    return tempHome;
}

From source file:com.linkedin.pinot.tools.admin.command.CreateSegmentCommand.java

@Override
public boolean execute() throws Exception {
    LOGGER.info("Executing command: {}", toString());

    // Load generator config if exist.
    final SegmentGeneratorConfig segmentGeneratorConfig;
    if (_generatorConfigFile != null) {
        segmentGeneratorConfig = new ObjectMapper().readValue(new File(_generatorConfigFile),
                SegmentGeneratorConfig.class);
    } else {/*from w  ww  . j  a v a2 s  .c  o  m*/
        segmentGeneratorConfig = new SegmentGeneratorConfig();
    }

    // Load config from segment generator config.
    String configDataDir = segmentGeneratorConfig.getDataDir();
    if (_dataDir == null) {
        if (configDataDir == null) {
            throw new RuntimeException("Must specify dataDir.");
        }
        _dataDir = configDataDir;
    } else {
        if (configDataDir != null && !configDataDir.equals(_dataDir)) {
            LOGGER.warn("Find dataDir conflict in command line and config file, use config in command line: {}",
                    _dataDir);
        }
    }

    FileFormat configFormat = segmentGeneratorConfig.getFormat();
    if (_format == null) {
        if (configFormat == null) {
            throw new RuntimeException("Format cannot be null in config file.");
        }
        _format = configFormat;
    } else {
        if (configFormat != _format && configFormat != FileFormat.AVRO) {
            LOGGER.warn("Find format conflict in command line and config file, use config in command line: {}",
                    _format);
        }
    }

    String configOutDir = segmentGeneratorConfig.getOutDir();
    if (_outDir == null) {
        if (configOutDir == null) {
            throw new RuntimeException("Must specify outDir.");
        }
        _outDir = configOutDir;
    } else {
        if (configOutDir != null && !configOutDir.equals(_outDir)) {
            LOGGER.warn("Find outDir conflict in command line and config file, use config in command line: {}",
                    _outDir);
        }
    }

    if (segmentGeneratorConfig.isOverwrite()) {
        _overwrite = true;
    }

    String configTableName = segmentGeneratorConfig.getTableName();
    if (_tableName == null) {
        if (configTableName == null) {
            throw new RuntimeException("Must specify tableName.");
        }
        _tableName = configTableName;
    } else {
        if (configTableName != null && !configTableName.equals(_tableName)) {
            LOGGER.warn(
                    "Find tableName conflict in command line and config file, use config in command line: {}",
                    _tableName);
        }
    }

    String configSegmentName = segmentGeneratorConfig.getSegmentName();
    if (_segmentName == null) {
        if (configSegmentName == null) {
            throw new RuntimeException("Must specify segmentName.");
        }
        _segmentName = configSegmentName;
    } else {
        if (configSegmentName != null && !configSegmentName.equals(_segmentName)) {
            LOGGER.warn(
                    "Find segmentName conflict in command line and config file, use config in command line: {}",
                    _segmentName);
        }
    }

    // Filter out all input files.
    File dir = new File(_dataDir);
    if (!dir.exists() || !dir.isDirectory()) {
        throw new RuntimeException("Data directory " + _dataDir + " not found.");
    }

    File[] files = dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(_format.toString().toLowerCase());
        }
    });

    if ((files == null) || (files.length == 0)) {
        throw new RuntimeException("Data directory " + _dataDir + " does not contain "
                + _format.toString().toUpperCase() + " files.");
    }

    // Make sure output directory does not already exist, or can be overwritten.
    File outDir = new File(_outDir);
    if (outDir.exists()) {
        if (!_overwrite) {
            throw new IOException("Output directory " + _outDir + " already exists.");
        } else {
            FileUtils.deleteDirectory(outDir);
        }
    }

    // Set other generator configs from command line.
    segmentGeneratorConfig.setDataDir(_dataDir);
    segmentGeneratorConfig.setFormat(_format);
    segmentGeneratorConfig.setOutDir(_outDir);
    segmentGeneratorConfig.setOverwrite(_overwrite);
    segmentGeneratorConfig.setTableName(_tableName);
    segmentGeneratorConfig.setSegmentName(_segmentName);
    if (_schemaFile != null) {
        if (segmentGeneratorConfig.getSchemaFile() != null
                && !segmentGeneratorConfig.getSchemaFile().equals(_schemaFile)) {
            LOGGER.warn(
                    "Find schemaFile conflict in command line and config file, use config in command line: {}",
                    _schemaFile);
        }
        segmentGeneratorConfig.setSchemaFile(_schemaFile);
    }
    if (_readerConfigFile != null) {
        if (segmentGeneratorConfig.getReaderConfigFile() != null
                && !segmentGeneratorConfig.getReaderConfigFile().equals(_readerConfigFile)) {
            LOGGER.warn(
                    "Find readerConfigFile conflict in command line and config file, use config in command line: {}",
                    _readerConfigFile);
        }
        segmentGeneratorConfig.setReaderConfigFile(_readerConfigFile);
    }
    if (_enableStarTreeIndex) {
        segmentGeneratorConfig.setEnableStarTreeIndex(true);
    }
    if (_starTreeIndexSpecFile != null) {
        if (segmentGeneratorConfig.getStarTreeIndexSpecFile() != null
                && !segmentGeneratorConfig.getStarTreeIndexSpecFile().equals(_starTreeIndexSpecFile)) {
            LOGGER.warn(
                    "Find starTreeIndexSpecFile conflict in command line and config file, use config in command line: {}",
                    _starTreeIndexSpecFile);
        }
        segmentGeneratorConfig.setStarTreeIndexSpecFile(_starTreeIndexSpecFile);
    }

    ExecutorService executor = Executors.newFixedThreadPool(_numThreads);
    int cnt = 0;
    for (final File file : files) {
        final int segCnt = cnt;

        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    SegmentGeneratorConfig config = new SegmentGeneratorConfig(segmentGeneratorConfig);
                    config.setInputFilePath(file.getAbsolutePath());
                    config.setSegmentName(_segmentName + "_" + segCnt);
                    config.loadConfigFiles();

                    final SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
                    driver.init(config);
                    driver.build();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
        cnt += 1;
    }

    executor.shutdown();
    return executor.awaitTermination(1, TimeUnit.HOURS);
}

From source file:eremeykin.pete.plotter.CartesianPlotterTopComponent.java

FilenameFilter filter() {
    return new FilenameFilter() {

        @Override//from   ww  w  .jav a 2  s .  co  m
        public boolean accept(File dir, String name) {
            return name.endsWith("Z.rpt");
        }
    };
}

From source file:org.opencastproject.episode.filesystem.FileSystemElementStore.java

/**
 * Returns a file {@link Option} from a storage path if one is found or an empty {@link Option}
 * /*from   w  ww .  j ava  2s.  c  om*/
 * @param storagePath
 *          the storage path
 * @return the file {@link Option}
 */
private Option<File> findStoragePathFile(final StoragePath storagePath) {
    final FilenameFilter filter = new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return FilenameUtils.getBaseName(name).equals(storagePath.getAssetId());
        }
    };
    final File containerDir = createFile(storagePath, none("")).getParentFile();
    return option(containerDir.listFiles(filter)).bind(new Function<File[], Option<File>>() {
        @Override
        public Option<File> apply(File[] files) {
            switch (files.length) {
            case 0:
                return none();
            case 1:
                return some(files[0]);
            default:
                throw new ElementStoreException("Storage path " + files[0].getParent()
                        + "contains multiple files with the same element id!: " + storagePath.getAssetId());
            }
        }
    });
}

From source file:net.morphbank.mbsvc3.webservices.RestService.java

public String[] getReqFileNames() {
    File dir = new File(folderPath);

    // It is also possible to filter the list of returned files.
    // This example does not return any files that start with `.'.
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.startsWith(FILE_PREFIX);
        }//from   w w w.j  a  v a 2 s .  c  o  m
    };
    String[] children = dir.list(filter);
    return children;
}

From source file:de.mprengemann.intellij.plugin.androidicons.settings.PluginSettings.java

private void scanForMaterialIconsAssets() {
    int categoriesCount = 0;
    int assetCount = 0;
    if (this.selectedMaterialIconsFile != null && this.selectedMaterialIconsFile.getCanonicalPath() != null) {
        File assetRoot = new File(this.selectedMaterialIconsFile.getCanonicalPath());
        final FilenameFilter drawableFileNameFiler = new FilenameFilter() {
            @Override//from  www  .  j a v  a 2  s .c o  m
            public boolean accept(File file, String s) {
                if (!FilenameUtils.isExtension(s, "png")) {
                    return false;
                }
                String filename = FilenameUtils.removeExtension(s);
                return filename.startsWith("ic_") && filename.endsWith("_black_48dp");
            }
        };
        final FilenameFilter folderFileNameFiler = new FilenameFilter() {
            @Override
            public boolean accept(File file, String s) {
                return !s.startsWith(".") && new File(file, s).isDirectory()
                        && !BLACKLISTED_MATERIAL_ICONS_FOLDER.contains(FilenameUtils.removeExtension(s));
            }
        };
        File[] categories = assetRoot.listFiles(folderFileNameFiler);
        if (categories != null) {
            categoriesCount = categories.length;
            if (categories.length >= 1) {
                for (File category : categories) {
                    File[] densities = category.listFiles(folderFileNameFiler);
                    if (densities != null && densities.length >= 1) {
                        File exDensity = densities[0];
                        File[] assets = exDensity.listFiles(drawableFileNameFiler);
                        assetCount += assets != null ? assets.length : 0;
                    }
                }
            }
        }
    }
    materialIconsFoundCategories.setText(categoriesCount + " categories");
    materialIconsFoundDrawables.setText(assetCount + " drawables");
}

From source file:org.openremote.modeler.service.impl.ResourceServiceImpl.java

@Override
public List<GraphicalAssetDTO> getUserImagesURLs() {
    File userFolder = new File(PathConfig.getInstance(configuration).userFolder(userService.getAccount()));
    String[] imageFiles = userFolder.list(new FilenameFilter() {
        @Override//  w ww  .  j  av  a 2 s .co m
        public boolean accept(File dir, String name) {
            String lowercaseName = name.toLowerCase();
            return (lowercaseName.endsWith("png") || lowercaseName.endsWith("gif")
                    || lowercaseName.endsWith("jpg") || lowercaseName.endsWith("jpeg"));
        }
    });
    List<GraphicalAssetDTO> assets = new ArrayList<GraphicalAssetDTO>();
    if (imageFiles != null) { // Seems we sometimes get a null (got it when tomcat was still starting)
        for (int i = 0; i < imageFiles.length; i++) {
            assets.add(new GraphicalAssetDTO(imageFiles[i],
                    getRelativeResourcePathByCurrentAccount(imageFiles[i])));
        }
    }
    return assets;
}

From source file:com.openedit.users.filesystem.XmlUserArchive.java

public List listUserNames() {
    List all = new ArrayList();
    ContentItem item = getPageManager().getRepository().get(getUserDirectory());
    File users = new File(item.getAbsolutePath());

    File[] files = users.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".xml");
        }/*from  www  .j  a  va  2s.co  m*/
    });

    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            String username = PathUtilities.extractPageName(files[i].getName());
            all.add(username);
        }
    }

    //      // Temporary
    //      item = getPageManager().getRepository().get("/WEB-INF/users");
    //      users = new File(item.getAbsolutePath());
    //
    //      files = users.listFiles(new FilenameFilter() {
    //         public boolean accept(File dir, String name) {
    //            return name.endsWith(".xml");
    //         }
    //      });
    //      if (files != null) {
    //         for (int i = 0; i < files.length; i++) {
    //            String username = PathUtilities.extractPageName(files[i]
    //                  .getName());
    //            if (!all.contains(username)) {
    //               all.add(username);
    //            }
    //         }
    //      }

    return all;
}