Example usage for org.apache.commons.io FilenameUtils isExtension

List of usage examples for org.apache.commons.io FilenameUtils isExtension

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils isExtension.

Prototype

public static boolean isExtension(String filename, Collection<String> extensions) 

Source Link

Document

Checks whether the extension of the filename is one of those specified.

Usage

From source file:com.htmlhifive.tools.jslint.dialog.CreateOptionFileDialog.java

/**
 * ??.//  w ww.jav a  2 s  .  c o m
 * 
 * @return .
 */
public String getOutputFilePath() {
    String outputDir = (String) wvOutpuDir.getValue();
    String optionFileName = (String) wvOptionFileName.getValue();
    if (!FilenameUtils.isExtension(optionFileName, "xml")) {
        optionFileName += ".xml";
    }
    return outputDir + "/" + optionFileName;
}

From source file:gobblin.compaction.mapreduce.avro.MRCompactorAvroKeyDedupJobRunner.java

public static Schema getNewestSchemaFromSource(Path sourceDir, FileSystem fs) throws IOException {
    FileStatus[] files = fs.listStatus(sourceDir);
    Arrays.sort(files, new LastModifiedDescComparator());
    for (FileStatus status : files) {
        if (status.isDirectory()) {
            Schema schema = getNewestSchemaFromSource(status.getPath(), fs);
            if (schema != null)
                return schema;
        } else if (FilenameUtils.isExtension(status.getPath().getName(), AVRO)) {
            return AvroUtils.getSchemaFromDataFile(status.getPath(), fs);
        }//ww  w  .  java 2  s .  co m
    }
    return null;
}

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 .ja v  a 2 s. c om*/
            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:de.mprengemann.intellij.plugin.androidicons.forms.MaterialIconsImporter.java

private void fillSizes() {
    final String lastSelectedSize = this.lastSelectedSize;
    sizeSpinner.removeAllItems();//www.  j  a  v  a  2 s. c o  m
    if (this.assetRoot.getCanonicalPath() == null) {
        return;
    }
    File assetRoot = new File(this.assetRoot.getCanonicalPath());
    assetRoot = new File(assetRoot, (String) categorySpinner.getSelectedItem());
    assetRoot = new File(assetRoot, DEFAULT_RESOLUTION);
    final String assetName = (String) assetSpinner.getSelectedItem();
    final FilenameFilter drawableFileNameFiler = new FilenameFilter() {
        @Override
        public boolean accept(File file, String s) {
            if (!FilenameUtils.isExtension(s, "png")) {
                return false;
            }
            String filename = FilenameUtils.removeExtension(s);
            return filename.startsWith("ic_" + assetName + "_");
        }
    };
    File[] assets = assetRoot.listFiles(drawableFileNameFiler);
    Set<String> sizes = new HashSet<String>();
    for (File asset : assets) {
        String drawableName = FilenameUtils.removeExtension(asset.getName());
        String[] numbers = drawableName.replaceAll("[^-?0-9]+", " ").trim().split(" ");
        drawableName = numbers[numbers.length - 1].trim() + "dp";
        sizes.add(drawableName);
    }
    List<String> list = new ArrayList<String>();
    list.addAll(sizes);
    Collections.sort(list);
    for (String size : list) {
        sizeSpinner.addItem(size);
    }
    if (list.contains(lastSelectedSize)) {
        sizeSpinner.setSelectedIndex(list.indexOf(lastSelectedSize));
    }
}

From source file:name.vysoky.epub.Book.java

/**
 * Recursive function - find files with given extension and add these files to given list.
 * @param directory directory for scan/*from w  w  w . ja v  a2s  .c  om*/
 * @param foundFiles found file list
 * @param extension filtered extension without dot
 */
private void findFilesWithExtension(File directory, List<File> foundFiles, String extension) {
    try {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory())
                    findFilesWithExtension(file, foundFiles, extension);
                if (file.isFile() && FilenameUtils.isExtension(file.getName(), extension))
                    foundFiles.add(file);
            }
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
}

From source file:com.silverpeas.util.FileUtil.java

/**
 * Indicates if the current file is of type image.
 *
 * @param filename the name of the file.
 * @return true is the file is of type image - false otherwise.
 *//*  w w w.j a v a 2  s  .  c om*/
public static boolean isImage(final String filename) {
    String mimeType = getMimeType(filename);
    if (DEFAULT_MIME_TYPE.equals(mimeType)) {
        return FilenameUtils.isExtension(filename.toLowerCase(), ImageUtil.IMAGE_EXTENTIONS);
    } else {
        return mimeType.startsWith("image");
    }
}

From source file:com.silverpeas.util.FileUtil.java

/**
 * Indicates if the current file is of type mail.
 *
 * @param filename the name of the file.
 * @return true is the file is of type mail - false otherwise.
 *//*from  w  w  w  .j  a  v  a2s . co m*/
public static boolean isMail(final String filename) {
    return FilenameUtils.isExtension(filename, Mail.MAIL_EXTENTIONS);
}

From source file:gobblin.compaction.mapreduce.MRCompactorJobRunner.java

@Override
public void run() {
    Configuration conf = HadoopUtils.getConfFromState(this.dataset.jobProps());

    // Turn on mapreduce output compression by default
    if (conf.get("mapreduce.output.fileoutputformat.compress") == null
            && conf.get("mapred.output.compress") == null) {
        conf.setBoolean("mapreduce.output.fileoutputformat.compress", true);
    }//www.j  a  va2 s.  co m

    // Disable delegation token cancellation by default
    if (conf.get("mapreduce.job.complete.cancel.delegation.tokens") == null) {
        conf.setBoolean("mapreduce.job.complete.cancel.delegation.tokens", false);
    }

    try {
        DateTime compactionTimestamp = getCompactionTimestamp();
        LOG.info("MR Compaction Job Timestamp " + compactionTimestamp.getMillis());
        if (this.dataset.jobProps().getPropAsBoolean(MRCompactor.COMPACTION_JOB_LATE_DATA_MOVEMENT_TASK,
                false)) {
            List<Path> newLateFilePaths = Lists.newArrayList();
            for (String filePathString : this.dataset.jobProps()
                    .getPropAsList(MRCompactor.COMPACTION_JOB_LATE_DATA_FILES)) {
                if (FilenameUtils.isExtension(filePathString, getApplicableFileExtensions())) {
                    newLateFilePaths.add(new Path(filePathString));
                }
            }

            Path lateDataOutputPath = this.outputDeduplicated ? this.dataset.outputLatePath()
                    : this.dataset.outputPath();
            LOG.info(String.format("Copying %d late data files to %s", newLateFilePaths.size(),
                    lateDataOutputPath));
            if (this.outputDeduplicated) {
                if (!this.fs.exists(lateDataOutputPath)) {
                    if (!this.fs.mkdirs(lateDataOutputPath)) {
                        throw new RuntimeException(
                                String.format("Failed to create late data output directory: %s.",
                                        lateDataOutputPath.toString()));
                    }
                }
            }
            this.copyDataFiles(lateDataOutputPath, newLateFilePaths);
            if (this.outputDeduplicated) {
                dataset.checkIfNeedToRecompact(datasetHelper);
            }
            this.status = Status.COMMITTED;
        } else {
            if (this.fs.exists(this.dataset.outputPath()) && !canOverwriteOutputDir()) {
                LOG.warn(String.format("Output paths %s exists. Will not compact %s.",
                        this.dataset.outputPath(), this.dataset.inputPaths()));
                this.status = Status.COMMITTED;
                return;
            }
            addJars(conf);
            Job job = Job.getInstance(conf);
            this.configureJob(job);
            this.submitAndWait(job);
            if (shouldPublishData(compactionTimestamp)) {
                if (!this.recompactAllData && this.recompactFromDestPaths) {
                    // append new files without deleting output directory
                    addFilesInTmpPathToOutputPath();
                    // clean up late data from outputLateDirectory, which has been set to inputPath
                    deleteFilesByPaths(this.dataset.inputPaths());
                } else {
                    moveTmpPathToOutputPath();
                    if (this.recompactFromDestPaths) {
                        deleteFilesByPaths(this.dataset.additionalInputPaths());
                    }
                }
                submitSlaEvent(job);
                LOG.info("Successfully published data for input folder " + this.dataset.inputPaths());
                this.status = Status.COMMITTED;
            } else {
                LOG.info("Data not published for input folder " + this.dataset.inputPaths()
                        + " due to incompleteness");
                this.status = Status.ABORTED;
                return;
            }
        }
        if (renameSourceDir) {
            MRCompactor.renameSourceDirAsCompactionComplete(this.fs, this.dataset);
        } else {
            this.markOutputDirAsCompleted(compactionTimestamp);
        }
        this.submitRecordsCountsEvent();
    } catch (Throwable t) {
        throw Throwables.propagate(t);
    }
}

From source file:com.pieframework.runtime.utils.azure.Cspack.java

private void stageStartupTasks(Role role, File roleDir) {

    File roleBin = null;//from  www  .j a  v a 2s .c o  m
    if (role.getProps().get("type") != null) {
        if (role.getProps().get("type").equals("WebRole")) {
            roleBin = new File(roleDir.getPath() + File.separatorChar + "bin");
        } else if (role.getProps().get("type").equals("WorkerRole")) {
            roleBin = new File(roleDir.getPath() + File.separatorChar);
        }
    }

    //Locate startup tasks and copy payloads into roleDir payloads   
    for (String key : role.getChildren().keySet()) {

        if (role.getChildren().get(key) instanceof Service) {
            Service s = (Service) role.getChildren().get(key);
            if (s.getProps().get("type") != null && s.getProps().get("type").equalsIgnoreCase("bootstrap")) {

                roleBin.mkdir();
                String query = s.getProps().get("installer");
                if (query != null) {
                    String fQuery = s.getProps().get("installer");
                    String nQuery = ResourceLoader.getResourceName(fQuery);
                    String pQuery = ResourceLoader.getResourcePath(fQuery);
                    Files bootstrap = (Files) s.getResources().get(nQuery);
                    if (bootstrap != null) {
                        List<File> flist = ResourceLoader.findPath(bootstrap.getLocalPath(), pQuery);
                        if (flist.size() == 1 && flist.get(0).exists()
                                && FilenameUtils.isExtension(flist.get(0).getPath(), "zip")) {

                            try {
                                Zipper.unzip(flist.get(0).getPath(), roleBin.getPath());
                            } catch (ZipException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }

                }
            }
        }
    }
}

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

private void fillColors() {
    final String lastSelectedColor = this.lastSelectedColor;
    colorSpinner.removeAllItems();/*from   w ww  .  j  a  v  a  2 s .c om*/
    if (this.assetRoot.getCanonicalPath() == null) {
        return;
    }
    File assetRoot = new File(this.assetRoot.getCanonicalPath());
    assetRoot = new File(assetRoot, (String) categorySpinner.getSelectedItem());
    assetRoot = new File(assetRoot, DEFAULT_RESOLUTION);
    final String assetName = (String) assetSpinner.getSelectedItem();
    final String assetSize = (String) sizeSpinner.getSelectedItem();
    final FilenameFilter drawableFileNameFiler = new FilenameFilter() {
        @Override
        public boolean accept(File file, String s) {
            if (!FilenameUtils.isExtension(s, "png")) {
                return false;
            }
            String filename = FilenameUtils.removeExtension(s);
            return filename.startsWith("ic_" + assetName + "_") && filename.endsWith("_" + assetSize);
        }
    };
    File[] assets = assetRoot.listFiles(drawableFileNameFiler);
    Set<String> colors = new HashSet<String>();
    for (File asset : assets) {
        String drawableName = FilenameUtils.removeExtension(asset.getName());
        String[] color = drawableName.split("_");
        drawableName = color[color.length - 2].trim();
        colors.add(drawableName);
    }
    List<String> list = new ArrayList<String>();
    list.addAll(colors);
    Collections.sort(list);
    for (String size : list) {
        colorSpinner.addItem(size);
    }
    if (list.contains(lastSelectedColor)) {
        colorSpinner.setSelectedIndex(list.indexOf(lastSelectedColor));
    }
}